I want to apply MouseEnter and MouseLeave EventTriggers to the entire row of a WPF GridView. I have used the code below to add the event triggers to a single column and these fire when the mouse moves over the text in that column.
<ListView x:Name="MyList" ItemsSource="{Binding listItems}">
<ListView.View>
<GridView>
<GridViewColumn Header="Tag" Width="100" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Tag}" Foreground="{Binding ForegroundColor}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseEnter">
<i:InvokeCommandAction Command="{Binding Path=MouseEnterCommand}"/>
</i:EventTrigger>
<i:EventTrigger EventName="MouseLeave">
<i:InvokeCommandAction Command="{Binding Path=MouseLeaveCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBlock>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Description" Width="300" DisplayMemberBinding="{Binding Description}"/>
<GridViewColumn Header="Qty" Width="80" DisplayMemberBinding="{Binding Qty}"/>
</GridView>
</ListView.View>
</ListView>
Rather than replicate the same Trigger code in each CellTemplate, is there a cleaner way to apply the triggers to the entire row, so that when the mouse enters or leaves any area on that row, the events are fired?
If you want to apply MouseEnter and MouseLeave EventTriggers to the entire row of listview, then you can rewrite the style of ListviewItem, like following: