C# – why is the DataGrid MouseDoubleClick event fired when you double click on the scrollbar

cnetwpf

Why is the DataGrid MouseDoubleClick event fired when i double click on the scrollbar or on the header?

Is there any way to avoid this and fire the event only when i double clicked inside the datagrid.

Best Answer

Scrollbar and header are part of the grid but do not handle double click, so the event "bubbles" up to the grid.

The inelegant solution is to somewhat find out "what was clicked" by the mean of event source or mouse coordinates.

But you can also do something like that (untested):

<DataGrid>
  <DataGrid.RowStyle>
    <Style TargetType="{x:Type DataGridRow}">
      <EventSetter Event="MouseDoubleClick" Handler="OnRowDoubleClicked"/>
    </Style>
  </DataGrid.RowStyle>
</DataGrid>