Stop CTRL-Click from affecting parent datagrid

自古美人都是妖i 提交于 2019-12-10 16:18:22

问题


I have a WPF DataGrid that has another datagrid declared within the RowDetailsTemplate;

<DataGrid name="dataGrid1" RowDetailsVisibilityMode="VisibleWhenSelected">
  ...
  <DataGrid.RowDetailsTemplate>
    <DataTemplate>
      <DataGrid name="dataGrid2">
        ...
      </DataGrid/>
    </DataTemplate>
  </DataGrid.RowDetailsTemplate>
</DataGrid>

When I CTRL-Click a row on the child DataGrid, it un-selects the parent datagrid's SelectedItem and hides the RowDetailsTemplate.

I assume this is some kind of Routed Event behaviour, but I've tried to catch MouseDown/LeftButtonMouseDown on the datagrid but no event is fired. I've also caught the SelectedItemChanged event on the child datagrid and set e.Handled = true; but the event still triggers on the parent.

How can I stop the parent datagrid from unselecting when CTRL-Clicking a child DataGridRow?


回答1:


Catching PreviewMouseLeftButtonDown at the child control, setting e.Handled = true and dataGridRow.IsSelected = !dataGridRow.IsSelected fixed this.



来源:https://stackoverflow.com/questions/9388655/stop-ctrl-click-from-affecting-parent-datagrid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!