I have a simple WPF ListView
with two columns defined. By default when you move the mouse over any part of a row it will show that row in a tracking appearance (I am using Windows 7 with Aero). Here is the Xaml for a simple example showing this working as expected...
<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>开发者_Go百科;
</ListView>
</Grid>
</Page>
I want to override the ListViewItem
style and customize the appearance of the row when tracking. Here is the sample Xaml I have added to the above ListView
...
<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>
It only shows the row as tracking when the mouse is directly over the text inside one of the two columns. If the mouse is between the drawn text or off the right hand side beyond the last column then it does not show as tracking.
It seems like the IsMouseOver
trigger only returns True if there is actual content under the mouse, when I want it to return True if the mouse is over any part of the row, even if that area of the row happens to be empty. Any ideas of how to solve this?
Set the border HorizontalAlignment to Stretch and give it a transparent (or otherwise default) background. this will give the mouse something to be over to highlight
精彩评论