【问题标题】:How do I make the combobox close when the dropdown button is pressed a second time?第二次按下下拉按钮时,如何关闭组合框?
【发布时间】:2011-07-18 15:01:27
【问题描述】:

我有一个带有一些自定义项目的 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>

【问题讨论】:

  • 您所期望的是正常行为,如果您再次单击,弹出窗口将关闭。你确定你是点击一次而不是双击?
  • 我想我需要将组合框点击模式设置为“按下”,自从突然修复后发生了很多变化。我怀疑设置点击模式解决了它,但我不确定

标签: wpf combobox wpf-controls


【解决方案1】:

使用您的控件(已删除 SelectionChanged 事件)在 PresentationFramework v4.0.30319 中对我来说可以正常工作。看看暂时删除SelectionChanged 事件是否能解决问题。

【讨论】:

  • 正如我所说,自从突然修复以来,已经发生了许多变化。但这也是其中之一,我希望这是修复它的原因,但我不能确定。尽管如此,将其标记为答案,因为它似乎最有可能。
猜你喜欢
  • 2020-01-23
  • 1970-01-01
  • 2021-03-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-13
  • 2019-12-01
  • 1970-01-01
相关资源
最近更新 更多