WPF ListView设置单选多选样式

本文介绍了如何在WPF中为ListView设置选中、焦点、鼠标悬停及失去焦点时的颜色样式,以实现单选或多选时的视觉效果。通过使用StyleSnooper工具,可以轻松查看并自定义这些WPF样式的细节。
摘要由CSDN通过智能技术生成

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=
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值