/ Published in: C#
Expand |
Embed | Plain Text
// create properties to represent program features public static class Commands { } // in WPF/XAML // reference your project namespace or the namespace containing the Commands class <Window ...xmlns:local="clr-namespace:RoutedCommandDemo"> // setup command bindings <Window.CommandBindings> <CommandBinding Command="{x:Static local:Commands.Foo}" CanExecute="Foo_CanExecute" Executed="Foo_Executed" /> </Window.CommandBindings> // setup keyboard short cuts <Window.InputBindings> <KeyBinding Command="{x:Static local:Commands.Foo}" Key="F" Modifiers="Ctrl" /> </Window.InputBindings> // have your button reference those commands as defined in command bindings <Button Command="{x:Static local:Commands.Foo}" ... /> // in code behind ... have events to handle commands/routed commands void Foo_CanExecute(object sender, CanExecuteRoutedEventArgs e) { ... } void Foo_Executed(object sender, ExecutedRoutedEventArgs e) { ... }
Comments
Subscribe to comments
You need to login to post a comment.

also referenced: StackOverflow: C#/WPF Implement Keyboard Shortcuts