2013-05-31 33 views
3

在我的WPF应用程序,我有一个自定义键绑定到我的命令之一:WPF - DataGrid的不予办理按Ctrl + A

<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" /> 

回答

6

您可以通过使用该删除包括结合的这种:

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

非常好,谢谢!我宁愿将它设置为“local:MainWindow.SelectAll”,所以它也会调用它。 –