WPF Keybinding in code behind RRS feed

  • Question

  • Hello, I would like to create a KeyBinding in code behind using this combo: Ctrl+Shift+Right+Left, so I did:

    KeyBinding b = new KeyBinding()
            Command = SpvCommands.ChangeUser,
            Key = Key.LeftCtrl,
            //Gesture = new KeyGesture(Key.LeftShiftKey);

    How to create the gesture with multiple combination?
    Wednesday, December 19, 2018 10:41 AM

All replies

  • There are several properties:

     g.GestureKey = Key.X;
     g.GestureModifier = ModifierKeys.Control;

    If you take a look at ModifierKeys:

    It's actually a flags, so you can combine any of them:

    g.GestureModifier = (ModifierKeys.Control | ModifierKeys.Shift );

    If you need multiple keys like leftctrl and rightctrl then you need two keybindings.

    You're binding a key press of a specific key, which can have modifiers such as ctrl / shift etc.

    Hope that helps.

    Technet articles: WPF: Layout Lab; All my Technet Articles

    Wednesday, December 19, 2018 11:36 AM