I know my answer is too late , but I hope this helps the future .
I like the answers of Guff and Heinzi, but you can only use one command to achieve the previous result. I usually use the help command
<Window.CommandBindings> <CommandBinding Command="{StaticResource Help}" Executed="HelpExecuted" /> </Window.CommandBindings>
and I use CommandParametr with every call e.g.
<Window.InputBindings> <KeyBinding Command="{StaticResource Help}" Key="A" Modifiers="Ctrl" CommandParameter="Case1"/> <KeyBinding Command="{StaticResource Help}" Key="B" Modifiers="Ctrl" CommandParameter="Case2"/> <KeyBinding Command="{StaticResource Help}" Key="C" Modifiers="Ctrl" CommandParameter="Case3"/> <KeyBinding Command="{StaticResource Help}" Key="D" Modifiers="Ctrl" CommandParameter="Case4"/> <MouseBinding Command="{StaticResource Help}" MouseAction="LeftDoubleClick" CommandParameter="Case5" /> </Window.InputBindings>
or
<Button Command="Help" CommandParameter="Case6" Content="Button"> <Button.InputBindings> <KeyBinding Command="{StaticResource Help}" Gesture="Ctrl+D" CommandParameter="Case7"/> </Button.InputBindings> </Button>
and in cs file
private void HelpExecuted(object sender, ExecutedRoutedEventArgs e) { string str = e.Parameter as string; switch (str) { case null://F1 Pressed default Help //Code break; case "Case1": //Code break; case "Case2": //Code break; case "Case3": //Code break; case "Case4": break; case "Case5": //Code break; case "Case6": //Code break; case "Case7": //Code break; } e.Handled = true; }
and if you use the MVVM pattern
private void HelpExecuted(object sender, ExecutedRoutedEventArgs e) { string str = e.Parameter as string; Mvvm_Variable.Action(Input: str); e.Handled = true; }
and move the switch to the ViewModule website. and Action is a method in the same ViewModule class.
Waleed AK Aug 31 2018-11-11T00: 00Z
source share