如果再次按下下拉按钮,如何关闭组合框呢?

时间:2011-07-18 15:01:27

标签: wpf combobox wpf-controls

我有一个带有一些自定义项目的wpf组合框。单击下拉按钮时,我希望第二次关闭下拉菜单,但重新打开它。我在其他应用程序中看到过类似的问题,我在网上寻找解决方案,但没有成功。这是迄今为止的代码:

        <ComboBox Name="ComboBoxColorLut"
                  IsEditable="False"
                  SelectionChanged="ComboBoxColorLut_SelectionChanged"                       
                  ToolTip="Color lookup table"
                  HorizontalContentAlignment="Stretch">
                    <ComboBox.ItemContainerStyle>
                        <Style TargetType="{x:Type ComboBoxItem}">
                            <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
                </Style>
            </ComboBox.ItemContainerStyle>
            <ComboBox.ItemTemplate>
                <DataTemplate>
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition ></RowDefinition>
                            <RowDefinition Height="3"></RowDefinition>
                        </Grid.RowDefinitions>
                        <TextBlock Grid.Row="0" Text="{Binding Path=Name}"></TextBlock>
                        <Rectangle Grid.Row="1" Fill="{Binding LinearGradientBrush}"></Rectangle>
                    </Grid>
                </DataTemplate>
            </ComboBox.ItemTemplate>
        </ComboBox>

1 个答案:

答案 0 :(得分:1)

使用您的控件(删除了SelectionChanged事件)可以使用PresentationFramework v4.0.30319正确地为我工作。看看暂时删除SelectionChanged事件是否解决了问题。