Click here to Skip to main content
14,697,418 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I want to create shortcuts for menus in WPF with two keys like that of Visual Studio
e.g.Ctrl+W,T

However I am able to create shortcuts using one key using below line of code,

this.InputBindings.Add(new KeyBinding(KeyBoardCommands.Open, new KeyGesture(Key.M, ModifierKeys.Control, "Ctrl+M")));

where KeyBoardCommands is the class in which I have defined the routed event Open.
this works fine for me. But I want to add support two keys with one modifier.
Please help me if anyone has any idea about it.

Thanks.
Posted
Updated 31-Mar-18 4:31am
Comments
Thomas Duwe 13-Nov-12 3:32am
   
I don't think this is something that can be done using only inputbindings.
What comes to mind is something like this: if user presses Ctrl+M, save the state and if the user presses again an M, then execute the appropiate command.

1 solution

InputGestureText property is used to add keyboard shortcut to the menu item. The following code adds CTRL+S to a menu item.

example:

<MenuItem IsCheckable="true" Header="Save" InputGestureText="Ctrl+S">
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900