Stop selection of selected item WPF ComboBox

I am currently working on the WPF user interface and I have a summary in my window. Therefore, I want the user to be able to select an item from this list, but when it is selected I do not want it to be highlighted in blue by default.

I guess there is some way to stop this in XAML, but so far I have not been able to find a solution.

Thanks.

PS I do not have access to Expression Blend, so if someone offers a solution, it may be in XAML

EDIT: just to make it easier for me to select the selected one, I mean, as soon as you select the value and the SelectionChanged event is fired, and the item is displayed in the combo box and the combo box is highlighted as follows: alt text

+4
source share
2 answers

You need to define the look of your choice with styles.

<Window.Resources> <Style TargetType="{x:Type ComboBoxItem}"> <Setter Property="Control.Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ComboBoxItem}"> <Border Background="{TemplateBinding Background}"> <Grid> <Grid.RowDefinitions> <RowDefinition /> <RowDefinition /> </Grid.RowDefinitions> <Border Margin="2" Grid.Row="0" Background="Azure" /> <ContentPresenter /> </Grid> </Border> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="Background" Value="Green" /> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> </Window.Resources> 

This style will be automatically applied to any ComboBoxes in the window:

 <StackPanel> <ComboBox> <ComboBoxItem>111</ComboBoxItem> <ComboBoxItem>222</ComboBoxItem> <ComboBoxItem>333</ComboBoxItem> <ComboBoxItem>444</ComboBoxItem> <ComboBoxItem>555</ComboBoxItem> </ComboBox> </StackPanel> 

You will see the following:

http://i.stack.imgur.com/b4pDo.png

UPD: To remove the selection from the selected item, you need to change the system brushes that are actually used for this purpose. Just add two additional styles:

  <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent"/> <SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Black"/> 
+8
source

Have you tried just setting the ComboBox.Background property?

-1
source

All Articles