I have a Combobox in WPF-MVVM and i have styled the combobox with changes in the popdown box and textbox of combobox.
When i scroll the combobox listitem thier background is pink is what i have chnaged. But after selecting a item from the combobox list, the selected value in combobox item has blue background. which is the default for a combobbox in both Windows Form and WPF.
See the image for more details.
How can i change that selectedtext background color in the combobox textbox control
The combobox has
IsEditable=True
property set
Navigate to the Properties window, and click the Background drop-down arrow, and choose Red or another color in the color picker.
A combobox is a selection control that combines a non-editable textbox and a drop-down listbox that allows users to select an item from a list. It either displays the current selection or is empty if there is no selected item.
You can do this:
<ComboBox.Resources>
<!--Selected color when the ComboBox is focused-->
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Yellow" />
<!--Selected color when the ComboBox is not focused-->
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Yellow" />
<!--selected text-->
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Yellow" />
</ComboBox.Resources>
(tested on ListBox but should work)
Another way is setting the ItemContainerStyle
property of the ComboBox
, and have a trigger depended on the current ComboBoxItem
selection state:
<ComboBox>
<ComboBox.Resources>
<Style TargetType="TextBlock">
<Style.Triggers>
<DataTrigger Binding="{Binding IsSelected, RelativeSource={RelativeSource AncestorType=ComboBoxItem}}" Value="True">
<Setter Property="Foreground" Value="White" />
</Trigger>
</Style.Triggers>
</Style>
</ComboBox.Resources>
<ComboBox.ItemContainerStyle>
<Style TargetType="ComboBoxItem" x:Key="ContainerStyle">
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="Red" />
</Trigger>
</Style.Triggers>
</Style>
</ComboBox.ItemContainerStyle>
</ComboBox>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With