How do I change the color of the item focus rectangle on a WPF ListView?
It's the color of the focus rectangle I mean to change, not the color of the selected item (which is green).
How do I change the color of the item focus rectangle on a WPF ListView?
It's the color of the focus rectangle I mean to change, not the color of the selected item (which is green).
To change the appearance of the focus visual of an item in the ListView, you will have to manipulate the FocusVisualStyle
that is part of the ItemContainerStyle
used by the ListView.
To illustrate, here is a simple example that turns the focus visual into a red dashed (dotted line) rectangle:
<ListView ...>
<ListView.ItemContainerStyle>
<!-- This is the style used by the item container of this ListView -->
<Style TargetType="ListViewItem">
<Setter Property="FocusVisualStyle">
<Setter.Value>
<!-- This is the style for the focus visual -->
<Style>
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate>
<Rectangle SnapsToDevicePixels="true"
Stroke="Red"
StrokeThickness="1"
StrokeDashArray="1 2"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Setter.Value>
</Setter>
</Style>
</ListView.ItemContainerStyle>
</ListView>