Hi I have two input key bindings on a WPF DataGrid, which will evoke coresponding command when key is pressed, like the following:
<DataGrid Grid.Row="1" IsReadOnly="False" Focusable="True"
AutoGenerateColumns="False" CanUserReorderColumns="False" CanUserDeleteRows="False"
EnableColumnVirtualization="False" EnableRowVirtualization="False" SelectionMode="Single"
ItemsSource="{Binding Path=QueryClauses}"
SelectedIndex="{Binding Path=SelectedQueryClauseIndex}">
<DataGrid.InputBindings>
<KeyBinding Key="Insert" Command="{Binding DataContext.InsertQueryClause, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=DataGrid}}"/>
<KeyBinding Key="Delete" Command="{Binding DataContext.DeleteQueryClause, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=DataGrid}}"/>
</DataGrid.InputBindings>
...
</DataGrid>
It works perfectly in the beginning, but after a while of editing/deleting on the editable DataGrid, the “Insert/Delete” command stops working, I debugged in the command, and the command was never fired, which means the DataGrid has somehow lost tracking of the keyboard input bindings.
I searched and find someone met a similar issue: https://social.msdn.microsoft.com/Forums/vstudio/en-US/0cdabbe0-b96f-43a2-bcb0-842d1766c2c7/why-does-my-inputbinding-stop-working?forum=wpf
The post explains that the control has lost the binding because somehow it sees the e.handled = true, so that the inputs were bypassed.
However, this post didn't tell how to fix it, so anyone have any ideas about this?
Thanks!