WPF ListBox Selection Color WPF ListBox Selection Color wpf wpf

WPF ListBox Selection Color


There are a few hacks you can do like overriding the system color key, but most likely you will want to provide a new template to achieve this. Here's a fairly nice looking one I put together:

<Style x:Key="ListboxItemStyle" TargetType="{x:Type ListBoxItem}">    <Setter Property="Margin" Value="1,2,1,1"/>    <Setter Property="HorizontalAlignment" Value="Stretch" />    <Setter Property="Background" Value="{StaticResource NormalItemBackground}" />    <Setter Property="Template">        <Setter.Value>            <ControlTemplate TargetType="{x:Type ListBoxItem}">                <Grid>                    <Border Background="{TemplateBinding Background}" />                    <Border Background="#BEFFFFFF" Margin="3,1">                        <Grid>                            <Grid.RowDefinitions>                                <RowDefinition />                                <RowDefinition />                            </Grid.RowDefinitions>                            <Border Margin="2,1,2,0" Grid.Row="0" Background="#57FFFFFF" />                        </Grid>                    </Border>                    <ContentPresenter Margin="8,5" />                </Grid>                <ControlTemplate.Triggers>                    <MultiTrigger>                        <MultiTrigger.Conditions>                            <Condition Property="IsMouseOver" Value="True" />                            <Condition Property="IsSelected" Value="False"/>                         </MultiTrigger.Conditions>                        <Setter Property="Background" Value="{StaticResource HotItemBackground}" />                    </MultiTrigger>                    <Trigger Property="IsSelected" Value="True">                        <Setter Property="Background" Value="{StaticResource SelectedItemBackground}" />                    </Trigger>                </ControlTemplate.Triggers>            </ControlTemplate>        </Setter.Value>    </Setter></Style><Style x:Key="ListBoxStyle" TargetType="{x:Type ListBox}">    <Setter Property="ItemContainerStyle" Value="{DynamicResource ListboxItemStyle}" />    <Setter Property="Margin" Value="3,3,2,1" /></Style>