Search code examples
wpfxamlitemscontrolkey-bindingsinputbinding

how to bind input key to itemscontrol in wpf


I have an items control which has items on a canvas, when I press delete I want to delete an item from the canvas:

<ItemsControl.InputBindings>
    <KeyBinding Command="{Binding DeleteItemCommand}" Key="Delete"/>
</ItemsControl.InputBindings>

However, the method in DeleteItemCommand is never called.

How can I achieve this?


Solution

  • The ItemsControl (or possibly something within) needs to be Focusable to receive keyboard input.