如何在Silverlights ComboBox中打开下拉菜单? [英] How keep drop down opened in silverlights ComboBox?

查看:96
本文介绍了如何在Silverlights ComboBox中打开下拉菜单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将ComboBox控件用作弹出窗口。我的ComboBox的项目是Grid。网格中有TreeView控件和两个Button。 TreeView的项目是CheckBoxes。

当我单击Buttons或CheckBoxes下拉菜单时,它保持打开状态,但是当我单击grid下拉菜单的其他部分时,我关闭了。

有什么办法吗?保持打开状态,直到我在ComboBox之外单击?

我在Google中看了很多东西,但是什么也没找到。

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>   

这是ComboBox

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>


推荐答案

听起来您的按钮没有填满所有空间

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:

尝试将背景设置为透明的矩形(不仅仅是具有0 alpha值的颜色,因为该颜色不可单击)。

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

(确保矩形也设置了IsHittestVisible)。

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

这篇关于如何在Silverlights ComboBox中打开下拉菜单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆