I have
<DataGrid Name="grid" MouseDoubleClick="Attributes_MouseDoubleClick" >
I need to unselect a row whenever a click event occurs anywhere else other than the Datagrid row.
i.e. grid.CurrentItem should be null
I need to fire a double-click event only on a row.
But, the problem is, once I select a row and double-click elsewhere on the grid(header, empty scrollviewer area, etc) the double-click event fires as expected but the CurrentItem is sometimes the selected row and sometimes null.
To prevent this behaviour.. I need to unselect the selected row.
Any ideas as to how I should approach this?
Thanks.
You can search the Visual Tree of the event source for an instance of type DataGridRow to determine if you double clicked on a row or somewhere else.
The following site Detecting Double Click Events on the WPF DataGrid contains good example.
I’ve include the code here in case the site is no longer available.
Here is the event handler for double click:
Here is the code to help search the Visual Tree: