开发者

WPF keyboard shortcuts for custom commands

开发者 https://www.devze.com 2023-02-13 07:51 出处:网络
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.

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?)

0

精彩评论

暂无评论...
验证码 换一张
取 消