I need to programmatically create a DataGrid and need to add a double click row event to it. How is this done in C#? I found this;
myRow.MouseDoubleClick += new RoutedEventHandler(Row_DoubleClick);
Although this does not work for me since I am binding the DataGrid.ItemsSource
to a collection and not manually adding in the rows.
Best Answer
You can do that in XAML by adding default style for DataGridRow under its resources section and declare event setter over there:
OR
In case want to do it in code behind. Set
x:Name
on grid, create style programatically and set the style as RowStyle.and in code behind:
AND
There is example of event handler: