views:

52

answers:

1

Hi all.
I use ComboBox control as popup. Item for my ComboBox is Grid. There is TreeView control and two Buttons in grid. Items of TreeView are CheckBoxes.
When I click on Buttons or CheckBoxes drop down keeps opened, but when I click on other part of grid drop down i closed.
Is there any way to keep it opened until I click outside of ComboBox?
I have looked a lot in Google, but haven't found anything.

<UserControl.Resources>        
    <common:HierarchicalDataTemplate x:Key="HierarchicalDataTemplate_AddDivision"  ItemsSource="{Binding DivisionIDs}">
        <StackPanel Orientation="Horizontal">
            <CheckBox IsChecked="{Binding IsChecked, Mode=TwoWay}" Click="CheckBox_Click" />
            <TextBlock Text="{Binding ToDisplay}"/>
        </StackPanel>
    </common:HierarchicalDataTemplate>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Background="White">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="0.5*"/>
        <ColumnDefinition Width="0.5*"/>
    </Grid.ColumnDefinitions>

    <Grid.RowDefinitions>
        <RowDefinition Height="0.90*"/>
        <RowDefinition Height="0.10*"/>
    </Grid.RowDefinitions>
    <controls:TreeView Height="250" x:Name="itemsToShow" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="230" 
                       Grid.ColumnSpan="2"  ItemTemplate="{StaticResource HierarchicalDataTemplate_AddDivision}" SelectedItemChanged="itemsToShow_SelectedItemChanged" />
    <Button Margin="28,0,22,5" Content="Ok" Grid.Row="1" d:LayoutOverrides="Height" Click="OkButton_Click"/>
    <Button Margin="23,0,27,5" Content="Cancel" Grid.Column="1" Grid.Row="1" d:LayoutOverrides="Height" Click="CancelButton_Click"/>  
</Grid>   

And this is ComboBox

<ComboBox Grid.Row="1" Width="100" Height="20" HorizontalAlignment="Left" VerticalAlignment="Top"  >
   <ComboBox.ItemTemplate>
      <DataTemplate>
       <my1:ShowDivisions x:Name="ShowDivs" Loaded="ShowDivs_Loaded" ParentComboBox="{Binding ElementName=addStr2}"/>                                            
      </DataTemplate>
  </ComboBox.ItemTemplate>
</ComboBox>
+1  A: 

It sounds like your buttons are not filling all the space in the dropdown part of the ComboBox.

In that case you just need to have a a clickable object behind the buttons to eat any stray mouse clicks:

Try a rectangle with the background set to Transparent (not just a colour with 0 alpha value, as that is not clickable).

(Make sure the rectangle has IsHittestVisible set as well).

Enough already
Thanks, for answer. I have tried Border control, but it didn't work. I will try your version.
Samvel Siradeghyan
@Samvel Siradeghyan: If you have any problems, post the Xaml for your ComboxBox. I can then test it and post a fix.
Enough already
I have tried as you say @HiTech Magic and get the same result. I will post XAML too.
Samvel Siradeghyan
I forgot to say that I created user control and set it as template for combo
Samvel Siradeghyan
@Samvel Siradeghyan: Where did you try and insert the rectangle or other background object? You need to edit the template of the combobox itself to do that. You could in theory add them to every item instead, but the rects would need to have a fixed width (not the best option). Go with changing the combobox template (best to use Expression Blend for that).
Enough already
Hi @HiTech Magic. I changed template of the combobox(as you say) insted of changing ItemTemplate(as did I) and now everything works fine. Thanks for answer. As I use custom control for items there was no need for background object.
Samvel Siradeghyan