Search code examples
wpfwpf-controlsc#-4.0commandkey-bindings

Is there a way to pass a parameter to a command through a keybinding done in code?


I am making a custom control I need to add some default keybindings, microsoft has already done with copy and paste in a textbox. However one of the keybindings needs to pass a parameter to the command which it is bound to. It is simple to do this in xaml, is there any way to do this in code?

this.InputBindings.Add(new KeyBinding(ChangeToRepositoryCommand, new KeyGesture(Key.F1)));

Solution

  • I found the answer:

    InputBindings.Add(new KeyBinding(ChangeToRepositoryCommand, new KeyGesture(Key.F1)) { CommandParameter = 0 });
    

    I apologize if my question was unclear.