WPF Changing ListboxItem Highlight Color when Selected WPF Changing ListboxItem Highlight Color when Selected wpf wpf

WPF Changing ListboxItem Highlight Color when Selected


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


If you wish to disable the highlighting when a listboxitem is selected or mouse over, you can use the below code.

<Style TargetType="ListBoxItem" x:Key="ListBoxItemStyle">    <Setter Property="IsSelected" Value="{Binding Content.IsSelected, Mode=TwoWay, RelativeSource={RelativeSource Self}}"/>    <Setter Property="Template">        <Setter.Value>            <ControlTemplate TargetType="ListBoxItem">                <ContentPresenter/>            </ControlTemplate>        </Setter.Value>    </Setter></Style><ListBox ItemContainerStyle="{StaticResource ListBoxItemStyle}"/>