How keep drop down opened in silverlights ComboBox?

一个人想着一个人 提交于 2019-12-11 08:35:04

问题


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:


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).



来源:https://stackoverflow.com/questions/3779472/how-keep-drop-down-opened-in-silverlights-combobox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!