Search code examples
wpfxamlshortcut

WPF double letter keybinding


I'm trying to recreate the same double letter key combo shortcut Visual Studio are using in WPF, where you use Alt+V+A to change view. I have tried different combinations of the code below.

<KeyBinding Key="V,A" Command="{Binding Path=ShowViewCommand}" CommandParameter="ArtifactView" Gesture="Alt+" />

Solution

  • I found a SO post says you can do this with a comma delimited list, but it didn't work for me.

    <Window.InputBindings>
        <KeyBinding Key="V,A" Modifiers="Alt" Command="{Binding TestCommand}"/>
    </Window.InputBindings>
    

    I think the commands you're seeing in visual studio are relying on the menu structure shortcuts.

    Like with notepad you can do Alt+F for file menu then S for save or X for exit. You could define a menu and sub menu. Make the command for the parent Alt+V using the _ before the letter V in the menu header or using an explicit inputgesture will invoke it. Which will "open" the menu if it's just a parent menu with no command.

    Then a sub menu item within SomeVing with Alt+A similarly.

    Or

    You could try this approach here: https://kent-boogaart.com/blog/multikeygesture Which inherits from keygesture.