Stop CTRL-Click from affecting parent datagrid

2019-06-28 01:37发布

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条回答
迷人小祖宗
2楼-- · 2019-06-28 02:00

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

查看更多
登录 后发表回答