wpf里ListView怎么设置选中行的颜色
我想让选中的那一行显示为蓝色,其他未选中的颜色不变,最好是在鼠标经过某一行时也能显示特定的颜色。wpf中ListView本来是自带这样的效果的,但是我想让显示效果扁平一些...
我想让选中的那一行显示为蓝色,其他未选中的颜色不变,最好是在鼠标经过某一行时也能显示特定的颜色。wpf中ListView本来是自带这样的效果的,但是我想让显示效果扁平一些,所以想更改一下效果,找了好久都不太对,求大神指教,急
展开
3个回答
展开全部
用触发器控制,代码如下~
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<ContentPresenter />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True"><!--鼠标悬停-->
<Setter Property="Background" Value="#FFDCDCDC"/><!--value中写你要的颜色的值-->
</Trigger>
<Trigger Property="IsSelected" Value="true"><!--选中-->
<Setter Property="Background" Value="#FF0078E6"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
展开全部
用触发器控制,代码如下~
<Style
TargetType="{x:Type
ListBoxItem}">
<Setter
Property="Template">
<Setter.Value>
<ControlTemplate
TargetType="{x:Type
ListBoxItem}">
<Border
Background="{TemplateBinding
Background}"
BorderBrush="{TemplateBinding
BorderBrush}"
BorderThickness="{TemplateBinding
BorderThickness}">
<ContentPresenter
/>
</Border>
<ControlTemplate.Triggers>
<Trigger
Property="IsMouseOver"
Value="True"><!--鼠标悬停-->
<Setter
Property="Background"
Value="#FFDCDCDC"/><!--value中写你要的颜色的值-->
</Trigger>
<Trigger
Property="IsSelected"
Value="true"><!--选中-->
<Setter
Property="Background"
Value="#FF0078E6"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style
TargetType="{x:Type
ListBoxItem}">
<Setter
Property="Template">
<Setter.Value>
<ControlTemplate
TargetType="{x:Type
ListBoxItem}">
<Border
Background="{TemplateBinding
Background}"
BorderBrush="{TemplateBinding
BorderBrush}"
BorderThickness="{TemplateBinding
BorderThickness}">
<ContentPresenter
/>
</Border>
<ControlTemplate.Triggers>
<Trigger
Property="IsMouseOver"
Value="True"><!--鼠标悬停-->
<Setter
Property="Background"
Value="#FFDCDCDC"/><!--value中写你要的颜色的值-->
</Trigger>
<Trigger
Property="IsSelected"
Value="true"><!--选中-->
<Setter
Property="Background"
Value="#FF0078E6"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
用触发器控制,代码如下~
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<ContentPresenter />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True"><!--鼠标悬停-->
<Setter Property="Background" Value="#FFDCDCDC"/><!--value中写你要的颜色的值-->
</Trigger>
<Trigger Property="IsSelected" Value="true"><!--选中-->
<Setter Property="Background" Value="#FF0078E6"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<ContentPresenter />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True"><!--鼠标悬停-->
<Setter Property="Background" Value="#FFDCDCDC"/><!--value中写你要的颜色的值-->
</Trigger>
<Trigger Property="IsSelected" Value="true"><!--选中-->
<Setter Property="Background" Value="#FF0078E6"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询