The following example demonstrates how to subscribe the MouseEnter and MouseLeave events of each DataRow using EventTriggers in an implicit style. The MouseEnter and MouseLeave event handlers are provided below.
| XAML |
Copy Code |
<Grid xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid"> <Grid.Resources> <xcdg:DataGridCollectionViewSource x:Key="cvs_orders" Source="{Binding Source={x:Static Application.Current}, Path=Orders}"/>
<Style TargetType="{x:Type xcdg:DataRow}"> <EventSetter Event="MouseEnter" Handler="DataRowMouseEnter"/>
<EventSetter Event="MouseLeave" Handler="DataRowMouseLeave"/> </Style> </Grid.Resources> <xcdg:DataGridControl x:Name="OrdersGrid" ItemsSource="{Binding Source={StaticResource cvs_orders}}" View="TableView.LunaNormalColorTheme"/> </Grid> |
The following code provides the implementation of the MouseEnter and MouseLeave event handlers, which change the background color of a DataRow when the mouse enters and resets it when the mouse leaves.
| VB.NET |
Copy Code |
Private Sub DataRowMouseEnter(ByVal sender As Object, ByVal e As MouseEventArgs)
Dim row As Xceed.Wpf.DataGrid.DataRow = TryCast(sender, Xceed.Wpf.DataGrid.DataRow)
If Not row Is Nothing Then row.Background = Brushes.Pink End If
End Sub Private Sub DataRowMouseLeave(ByVal sender As Object, ByVal e As MouseEventArgs)
Dim row As Xceed.Wpf.DataGrid.DataRow = TryCast(sender, Xceed.Wpf.DataGrid.DataRow)
If Not row Is Nothing Then row.Background = DataGridControl.GetParentDataGridControl( row ).Background End If
|
| C# |
Copy Code |
private void DataRowMouseEnter( object sender, MouseEventArgs e ) {
Xceed.Wpf.DataGrid.DataRow row = sender as Xceed.Wpf.DataGrid.DataRow;
if( row != null ) { row.Background = Brushes.Pink; }
} private void DataRowMouseLeave( object sender, MouseEventArgs e ) {
Xceed.Wpf.DataGrid.DataRow row = sender as Xceed.Wpf.DataGrid.DataRow;
if( row != null ) { row.Background = DataGridControl.GetParentDataGridControl( row ).Background; } } |