In my application, I have defined the following style for TextBlocks.
<Style TargetType="{x:Type TextBlock}">
<Setter Property="FontFamily" Value="Arial"/>
<Setter Property="FontSize" Value="11"/>
<Setter Property="Foreground" Value="{StaticResource TextBrush}"/>
<Setter Property="Opacity" Value="1.0"/>
<Style.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Opacity" Value="0.40"/>
</Trigger>
</Style.Triggers>
</Style>
The style is intentionally defined at the highest level of my application so that it applies to all TextBlocks by default.
The problem is that this style breaks the behaviour of TextBlocks in ComboBoxes. Normally, the selected item in a ComboBox has its Foreground colour change to white. With this style applied however, the foreground colour of the text does not change.
How can I trigger the text to change colour when the TextBlock in a ComboBox is highlighted?
I resolved this issue by moving the styles out of
app.xamland into a separate resource dictionary that I include as needed in my application Window & Pages.This stops the
TextBlockstyle from affecting the colour of the text in theComboBox. Finally, to achieve the text colour I wanted on all items I overrode the following default system colours with my own.