c# - WPF - DataGrid 不应处理 Ctrl+A

标签 c# wpf datagrid command key-bindings

在我的 WPF 应用程序中,我有一个自定义键绑定(bind)到我的命令之一:

<KeyBinding Modifiers="Control" Key="A" Command="local:MainWindow.SelectAll" />

(它的作用是选择带有边界框的图像上的整个区域供以后处理。)

主窗口中还有一个DataGrid。 Ctrl+A 键在应用程序上运行良好,直到我单击 DataGrid。从那时起,DataGrid 将处理它(但不执行任何操作,因为它不是多选网格)。

我怎样才能实现 DataGrid 不处理 Ctrl+A,所以它总是会触发我的命令?

如果有帮助,这是我的 DataGrid:

<DataGrid Name="myDataGrid" ItemsSource="{Binding}" SelectionMode="Single"
EnableRowVirtualization="True" SelectedCellsChanged="myDataGrid_SelectedCellsChanged"
IsReadOnly="True" />

最佳答案

您可以使用以下方法删除此类包含的绑定(bind):

<DataGrid>  
<DataGrid.InputBindings>
<KeyBinding Gesture="Ctrl+A" Command="ApplicationCommands.NotACommand"/>  
</DataGrid.InputBindings>  
</DataGrid>

关于c# - WPF - DataGrid 不应处理 Ctrl+A,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16855921/

相关文章:

c# - 如何在背景上方插入图像

c# - 如何判断文件是否可执行?

wpf - 使用参数将 WPF GridViewColumn 绑定(bind)到方法

wpf - WPF 的 XAML 中的 margin 百分比

grails - 用于组合框的jQuery easyui数据网格编辑器未随grails一起加载

c# - 在 Netbeans 中添加支持使用 WCF 流服务进行流处理的 Java Web 服务客户端?

c# - 使用一种通用类型创建自定义可迭代字典

wpf - 开口WPF用户控件的winform窗口缩小父的winform窗口

数百万行的 JavaScript 数据网格

c# - wpf 数据网格复选框列 : how to enable/disable checkboxes