停止CTRL单击不影响父数据网格 [英] Stop CTRL-Click from affecting parent datagrid

查看:58
本文介绍了停止CTRL单击不影响父数据网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WPF DataGrid,在RowDetailsTemplate中声明了另一个数据网格;

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>

当我CTRL-单击子DataGrid上的一行时,它将取消选择父DataGrid的 SelectedItem 并隐藏 RowDetailsTemplate

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

我认为这是一些路由事件的行为,但我试图在数据网格上捕获 MouseDown / LeftButtonMouseDown ,但未触发任何事件。我还在子数据网格上捕获了 SelectedItemChanged 事件,并设置了 e.Handled = true; ,但该事件仍然存在

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.

CTRL -单击子DataGridRow时,如何阻止父datagrid取消选择?

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

推荐答案

在子控件上捕获 PreviewMouseLeftButtonDown ,将 e.Handled = true dataGridRow.IsSelected =!dataGridRow.IsSelected 修复了此问题。

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

这篇关于停止CTRL单击不影响父数据网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆