Q:

Remove selection highlight from custom WPF ListView

I have a ListView with custom ItemTemplate for the items.
I want to remove or change the visual effect for selection.
So far I tried assgining a custom ItemContainerStyle to my ListView:
<ListView x:Name="DispList" ItemContainerStyle="{StaticResource MySty}" ItemTemplate="{StaticResource Mine}">

</ListView>

And under resources, defining the style as follows:
<Style TargetType="{x:Type ListViewItem}" x:Key="MySty">
        <Style.Resources>
            <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent"/>
        </Style.Resources>
</Style>

Unfortunately, this does not work. What am I missing?

A:

This approach of trying to override the system colours doesn't work on Windows 8 and later.
You need to modify the ControlTemplate of the ListViewItem container.
Refer to: ListView Selected Item Style Override
An example:
<ListView>
    <ListView.ItemContainerStyle>
        <Style TargetType="{x:Type ListViewItem}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ListBoxItem}">
                        <Border x:Name="RootBorder">
                            <ContentPresenter/>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter TargetName="RootBorder" Property="BorderBrush" Value="Red"/>
                                <Setter TargetName="RootBorder" Property="BorderThickness" Value="1"/>
                            </Trigger>
                            <!--<Trigger Property="IsSelected" Value="True">
                                <Setter TargetName="RootBorder" Property="Background" Value="LightBlue"/>
                            </Trigger>-->
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </ListView.ItemContainerStyle>
    <ListViewItem>123</ListViewItem>
    <ListViewItem>456</ListViewItem>
    <ListViewItem>789</ListViewItem>
</ListView>

