dov
dov

Reputation: 27

Getting the xaml name of a control using a MouseMove event

I have 2 DataGrid's.

 <DataGrid x:Name="dataGrid1"  />


 <DataGrid x:Name="dataGrid2"  />

Is it possible to get the xaml Name of the DataGrid I'm currently on from a MouseMove event?

Thanks!

Edit: I'm using a third party source - Syncfusion in order to create a SfDataGrid.

Upvotes: 1

Views: 293

Answers (1)

WPFGermany
WPFGermany

Reputation: 1647

try this:

ABC.xaml

<SfDataGrid x:Name="dataGrid1" MouseEnter="DG_OnMouseEnter" />
<SfDataGrid x:Name="dataGrid2" MouseEnter="DG_OnMouseEnter" />

ABC.xaml.cs [CodeBehind]

private void DG_OnMouseEnter(object sender, MouseEventArgs e)
{
    Debug.WriteLine(((FrameworkElement) sender).Name);
    if (sender is SfDataGrid) e.Handled = true; //prevent event-execution of childs
}

Upvotes: 1

Related Questions