Subscribing to the Events of an Element
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
- C#
- VB.NET
<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>
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;
}
}
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
End Sub