0

I have a problem with the use of key bindings in an wpf application, but lets start at the beginning:

I have a window which contains various textboxes and a tabcontrol. The tabcontorl consists of two tabs. One of the tabs contains a datagrid with 0 to n items. If the datagrid contains at least one item, the user can remove the selected item from the underlying ObservableCollection.

If I use the buttons I designed for this, everything works fine. But I also want the user to be able to remove the selected item via a key binding.

Therefore I declared the following key binding within the window (the user should be able to use the key binding regardless which control has the focus).

<Window.InputBindings>
    <KeyBinding Key="Right" Modifiers="Control" Command="{Binding CmdRemove}" />
</Window.InputBindings>

The command to be executed is of type ICommand and bound to the view model of the window.

So now the point where I am lost:

The key binding only works, if the tab item has the focus. Neither does it work if the focus is on some other control of the window (then the last selected item should be removed), nor if the item to remove is selected directly within the DataGrid.

Am I missing something crucial?

Thanks in advance.

Alex
  • 86
  • 4
  • 3
    Your key sequence probably gets "eaten" before it gets to your inputbinding, see http://stackoverflow.com/questions/12941707/keybinding-in-usercontrol-doesnt-work-when-textbox-has-the-focus for a similar problem – Tommy Grovnes May 20 '15 at 08:18
  • Solved the problems. Thanks! – Alex May 21 '15 at 07:50

0 Answers0