Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF - DataGrid shall not handle Ctrl+A

In my WPF application I have a custom key binding to one of my commands:

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

(What it does is it select the whole area on an image with a bounding box for later processing.)

There is also a DataGrid in the main window. The Ctrl+A key works well on the application until I once clicked into the DataGrid. From that point, the DataGrid handles it (but doesn't do anything since it is not a multiselect grid).

How can I achieve the the DataGrid doesn't handle Ctrl+A, so it will always fire my command?

Here's my DataGrid if that helps:

<DataGrid Name="myDataGrid" ItemsSource="{Binding}" SelectionMode="Single"
EnableRowVirtualization="True" SelectedCellsChanged="myDataGrid_SelectedCellsChanged"
IsReadOnly="True" />
like image 573
Adam Szabo Avatar asked Mar 23 '23 18:03

Adam Szabo


1 Answers

You can remove this kind of included binding by using this:

<DataGrid>  
<DataGrid.InputBindings>
<KeyBinding Gesture="Ctrl+A" Command="ApplicationCommands.NotACommand"/>  
</DataGrid.InputBindings>  
</DataGrid>
like image 196
ceciliaSHARP Avatar answered Mar 26 '23 09:03

ceciliaSHARP