WPF keyboard shortcuts for custom commands
I'm programming an application in WPF/C#, and I'm currently using the method below to handling keyboard shortcut presses. And I hate it so much.
private void MainWnd_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.F1 && Keyboard.Modifiers.HasFlag(ModifierKeys开发者_开发问答.Control))
{
DoCtrlF1Function();
}
}
Now undoubtedly I'd use command bindings, but in the XAML, if I put a name that's not the built-in ones, I get an exception using the WPF editor. Is there a better way to do this?
(I.e. add my own commands in, would this be like RoutedCommand?)
精彩评论