我有一个简单的WPF ListView
,定义了两个列。默认情况下,当您将鼠标移到行的任何部分时,它会以跟踪外观显示该行(我正在使用带Aero的Windows 7)。这是一个简单示例的Xaml,展示了这个功能如预期的工作...
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib">
<Grid>
<ListView>
<ListView.View>
<GridView>
<GridViewColumn Header="First" Width="200"/>
<GridViewColumn Header="Second" Width="200"/>
</GridView>
</ListView.View>
<sys:DateTime>1/2/3</sys:DateTime>
<sys:DateTime>4/5/6</sys:DateTime>
<sys:DateTime>7/8/9</sys:DateTime>
<sys:DateTime>10/11/12</sys:DateTime>
</ListView>
</Grid>
</Page>
我希望覆盖ListViewItem
样式,并在跟踪时自定义行的外观。这是我添加到上面的ListView
的示例Xaml...
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Border x:Name="Bd">
<GridViewRowPresenter />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Bd" Property="Background" Value="Red"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListView.ItemContainerStyle>
只有当鼠标直接悬停在两列文本内部的文本上时,它才会显示为跟踪。如果鼠标在绘制的文本之间或超出最后一列的右侧,则不会显示为跟踪。
似乎 IsMouseOver 触发器仅在鼠标下方实际存在内容时返回 True,但我希望它在鼠标悬停在行的任何部分时都返回 True,即使该行的该区域恰好为空。有什么解决方法吗?