Here is my code for implementing multiple character shortcuts like Alt + P + A in WPF MVVM.
Add this to XAML (attached behavior for the KeyDown event):
cb:ShortCutBehavior.Command="{Binding Shortcuts.CmdKeyPressed}"
Add this to your view model:
ShortCuts Shortcuts = new ShortCuts( this ); //Add Plenty of shortcuts here until your heart is desired Shortcuts.AddDoubleLetterShortCut( AddOrganization, Key.P, Key.A, ModifierKeys.Alt, true); Shortcuts.AddSingleLetterShortCut( CmdAddNewAgreement, Key.A, ModifierKeys.Alt);
These are two examples of adding shortcuts. The first is a double label with a letter: Alt + P + A , which launches the AddOrganization () method, and the second is a label with a single letter: Alt + A , which runs ICommand CmdAddNewAgreemnt.
Both AddDoubleLetterShortCut and AddSingleLetterShortCut are overloaded to accept actions or ICommands.
This is one of my first attempts to generalize something, so you can accept this idea and make it suitable for you.
Terence Apr 03 '13 at 16:14 2013-04-03 16:14
source share