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.
精彩评论