双击滚动条时,为什么会触发DataGrid MouseDoubleClick事件?

HB *_*AAM 14 .net c# wpf

当我双击滚动条或标题时,为什么会触发DataGrid MouseDoubleClick事件?

有没有办法避免这种情况,只有当我在数据网格内双击时才会触发事件.

Nic*_*uet 13

滚动条和标题是网格的一部分,但不处理双击,因此事件"冒泡"到网格.

不优雅的解决方案是通过事件源或鼠标坐标的平均值找出"被点击的内容".

但你也可以这样做(未经测试):

<DataGrid>
  <DataGrid.RowStyle>
    <Style TargetType="{x:Type DataGridRow}">
      <EventSetter Event="MouseDoubleClick" Handler="OnRowDoubleClicked"/>
    </Style>
  </DataGrid.RowStyle>
</DataGrid>
Run Code Online (Sandbox Code Playgroud)