开发者

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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜