我需要一些帮助。我不明白为什么我找到的解决方案都不适合我的案例。让我们考虑一个ListView这些项目:在鼠标上更改ListViewItem背景色
<ListView.Items>
<ListViewItem>
<TextBlock xml:space="preserve"> 1 <Bold>I'm bold</Bold> </TextBlock>
</ListViewItem>
<ListViewItem>
<TextBlock xml:space="preserve"> 2 Im not </TextBlock>
</ListViewItem>
</ListView.Items>
最初悬停的每一行,我看到TextBlock的亮点在其默认的淡蓝色。它只强调文字区域:
我不想那个高亮我想整个行中的一个,我想决定颜色。我也希望选择时整行的亮点:
我一直在玩样式,触发器或ItemContainerStyle。我意识到我必须考虑文本框的背景以及带有文本的区域的ListViewItem。整行的背景似乎是ListView.ItemContainerStyle的业务。
添加样式FOT TextBox的结果:
<Style x:Key="TextBlockStyle" TargetType="{x:Type TextBlock}">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Foreground" Value="Black" />
<Setter Property="Background" Value="White"/>
</Trigger>
</Style.Triggers>
</Style>
<ListView Grid.Column="1" Margin="0" HorizontalContentAlignment="Stretch" BorderThickness="0" >
<ListView.Resources>
<Style BasedOn="{StaticResource TextBlockStyle}" TargetType="{x:Type TextBlock}" />
</ListView.Resources>
然后,添加另一种风格,试图将文本框下摆脱ListView的背景:
<Style x:Key="ListViewItemStyle" TargetType="{x:Type ListViewItem}">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="Gold" />
</Trigger>
</Style.Triggers>
</Style>
<ListView Grid.Column="1" Margin="0" HorizontalContentAlignment="Stretch" BorderThickness="0" >
<ListView.Resources>
<Style BasedOn="{StaticResource TextBlockStyle}" TargetType="{x:Type TextBlock}" />
<Style BasedOn="{StaticResource ListViewItemStyle}" TargetType="{x:Type ListViewItem}" />
</ListView.Resources>
但是这完全没有效果。
,并试图以突出整个行与这不起作用:
<ItemsControl.ItemContainerStyle>
<Style>
<Style.Triggers>
<Trigger Property="Control.IsMouseOver" Value="True">
<Setter Property="Control.Background" Value="Gold" />
</Trigger>
</Style.Triggers>
</Style>
</ItemsControl.ItemContainerStyle>
并试图几个小时几个其他建议。这一个: Remove the mouse over effect on a ListView in WPF避免悬停的文本高亮,无论是为TextBox和ListViewItem,但我不知道如何改变整个行的背景。 有人可以提供我想要做的一个例子吗?
更改DataTemplate中容器的背景。 – AnjumSKhan