DevNoob
DevNoob

Reputation: 546

WPF combo box text color doesn't change

I need to make the text of the combobox items in a combobox change color to white when the item is selected. I can currently change the background color under those conditions however setting <Setter Property="Foreground" Value="White"/> inside of the same style trigger that changes the background color doesn't change anything.

Sample XAML

<Style x:Key="ComboBoxItemStyle" TargetType="{x:Type ComboBoxItem}">
  <Style.Triggers>
            <Trigger Property="IsSelected" Value="True">
                <Setter Property="Background" Value="#FF648CBE"/>
                <Setter Property="Foreground" Value="White"/>
            </Trigger>
  </Style.Triggers>
</Style>

Also, if i change the foreground setter to change the font size or boldness, that works. I am not sure why I can do that but not change the color.

Upvotes: 2

Views: 2679

Answers (1)

DevNoob
DevNoob

Reputation: 546

It turns out that I did not understand the WPF styling hierarchy. Elsewhere in the XAML my combobox foreground color was being overridden by a data binding styling block. Once that was removed, the foreground color was able to be changed.

Upvotes: 3

Related Questions