Reputation: 45106
With .NET 4.0 it appears highlighting of ListBox and ListView has changed
Below is code I have used for years in several places on .NET 3.5 and highlight when not focused has stopped working on 4.0 and 4.5
<ListBox.ItemContainerStyle>
<Style>
<Style.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Red"/>
<!-- Background of selected item when focussed -->
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Pink"/>
<!-- Background of selected item when not focussed -->
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Yellow" />
</Style.Resources>
</Style>
</ListBox.ItemContainerStyle>
ListBox SelectedItem Background
Upvotes: 3
Views: 605
Reputation: 45106
With .NET 4.0 there are some new SytemColors
This appears to be the .NET 4.0 way
According to comment this changed in 4.5 - not 4.0.
<ListBox.ItemContainerStyle>
<Style>
<Style.Resources>
<!-- Foregroud of selected item when focussed -->
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Red"/>
<!-- Foregroud of selected item when not focussed -->
<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightTextBrushKey}" Color="Green"/>
<!-- Background of selected item when focussed -->
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Pink"/>
<!-- Background of selected item when not focussed -->
<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="Yellow" />
</Style.Resources>
</Style>
</ListBox.ItemContainerStyle>
At first I though the definition of ControlBrushKey had changed but it has not
It appears the behavior of ControlBrushKey has changed in this situation
Note the behavior changes with GridView
Upvotes: 2