WPF ListView选中颜色设置(单选多选)
ListView选中某型Item时自动进行高亮显示,下面代码可支持设置Item选中的颜色、Item有焦点的颜色、鼠标在Item上的颜色、失去焦点的颜色。
wpf样式可通过StyleSnooper工具进行查看
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Window.Resources>
<Style x:Key="listviewItemKey" TargetType="ListViewItem">
<Style.Resources>
<SolidColorBrush x:Key="BrushFocus" Color="{DynamicResource {x:Static SystemColors.HighlightColorKey}}"/>
</Style.Resources>
<Setter Property="Margin" Value="15,10"/>
<Setter Property="Background" Value="LightGray"/>
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate TargetType="ListViewItem">
<Border BorderThickness="{TemplateBinding Border.BorderThickness}"
Padding="{TemplateBinding Control.Padding}"
BorderBrush="{TemplateBinding Border.BorderBrush}"
Background="{TemplateBinding Panel.Background}"
Name="Bd"
SnapsToDevicePixels="True">
<ContentPresenter
Content="{TemplateBinding ContentControl.Content}"
ContentTemplate=