开发者

How do I make the combobox close when the dropdown button is pressed a second time?

开发者 https://www.devze.com 2023-03-20 21:50 出处:网络
I have a wpf combobox with some custom items. When the dropdown button is clicked the second time I would like the dropdown to close but instead it is reopened. I\'ve seen similar issues in other appl

I have a wpf combobox with some custom items. When the dropdown button is clicked the second time I would like the dropdown to close but instead it is reopened. I've seen similar issues in other applications and I've looked for a solution online but without succes. Here's the code so far:

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


Using your control (having removed the SelectionChanged event) works correctly for me with PresentationFramework v4.0.30319. See if temporarily removing the SelectionChanged event fixes the problem.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号