Set background color for selected items in a ListBox Set background color for selected items in a ListBox wpf wpf

Set background color for selected items in a ListBox


You specify the SelectedItem Background for a ListBox with the SystemColors.HighlightBrushKey (focused) and SystemColors.ControlBrushKey (not focused)

<Style.Resources>    <!-- Background of selected item when focussed -->    <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}"                     Color="Green"/>    <!-- Background of selected item when not focussed -->    <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}"                     Color="LightGreen" /></Style.Resources> 


<ListBox.Resources>    <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}">SteelBlue</SolidColorBrush></ListBox.Resources>

If you want this to apply out of focus as well you need to override an additional key:

<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}">SteelBlue</SolidColorBrush>