I have a WPF Window
which basically has a ListBox
which displays a list of items.
I then have a ListView
basically displaying the details of the SelectedItem
in the ListBox
.
The thing is, when the focus is not on the ListBox
anymore, the highlighting color disappears and I cannot see which master item was selected anymore.
Do you know how I can solve this? (ie. making sure that the item stays highlighted)
The quickest way is to use a style on the ListBoxItem to override the default System colors:
<Style TargetType="ListBoxItem">
<Style.Resources>
<!--SelectedItem with focus-->
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}"
Color="LightBlue" Opacity=".4"/>
<!--SelectedItem without focus-->
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}"
Color="LightBlue" Opacity=".4"/>
</Style.Resources>
</Style>
This is kind of a shortcut to the slightly more complex (but easier to control) method of defining the ItemTemplate for the list items. There are plenty of examples of that online, so I won't put that here.
Check out this MSDN blog post
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