先上对比图:
原生的ListView列表图:
去除背景的ListView效果图: 更换了当前选中项的字体颜色,去除了ListView自带的背景框和背景颜色
给ListView分别添加鼠标移上去时和选中时的背景颜色和字体颜色效果图:
下面是ListView的样式代码:
<!-- 设置ListView的绑定数据源和基础样式-->
<ListView ItemsSource="{Binding Data}" Name="listView"
SelectedItem="{Binding SelectedData}"
Background="Transparent"
VerticalAlignment="Top"
BorderThickness="0" Grid.Row="1">
<!-- 绑定命令,选中项改变时触发的事件-->
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding ItemChangeCommand}" CommandParameter="10" />
</i:EventTrigger>
</i:Interaction.Triggers>
<ListView.Resources>
<!-- 重写ListViewItem样式-->
<Style TargetType="{x:Type ListViewItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListViewItem}">
<Border Name="Bd"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Padding="{TemplateBinding Padding}"
SnapsToDevicePixels="true">
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Setter Property="Cursor" Value="Hand"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Foreground" Value="Black"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="VerticalAlignment" Value="Top"/>
<Setter Property="FontSize" Value="14"/>
<Style.Triggers>
<!--触发器-->
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="Orange"/>
<Setter Property="BorderBrush" Value="Red"/>
</Trigger>
<Trigger Property="IsSelected" Value="true">
<Setter Property="Background" Value="Blue"/>
<Setter Property="Foreground" Value="#096fc8"/>
</Trigger>
</Style.Triggers>
</Style>
</ListView.Resources>
<ListView.ItemTemplate>
<DataTemplate>
<Grid FocusVisualStyle="{x:Null}">
<TextBlock>
<TextBlock.Style>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Margin" Value="0,8,0,0"/>
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<!--绑定每项显示的内容-->
<Setter Property="Text" Value="{Binding value}"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Foreground" Value="#096fc8"></Setter>
</Trigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
源码:放在CSDN下载了
点击这里下载源码