如何分配按Ctrl +,(控制加逗号)作为键盘快捷方式WPF菜单项? [英] How to assign Ctrl+, (control plus comma) as the keyboard shortcut to a WPF menu item?

查看:964
本文介绍了如何分配按Ctrl +,(控制加逗号)作为键盘快捷方式WPF菜单项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想指定快捷键<大骨节病>控制 + <大骨节病>,(控制加逗号)首选项...菜单项。 ?我该怎么做了。



有一个 Key.OemComma 中的 枚举。我已经使用 Key.OemComma 如下面的代码示例所示。这工作正常功能明智的。但是GUI明智:菜单项显示为




  • 首选项(按Ctrl + OemComma)



而不是




  • 首选项(按Ctrl +)



示例代码

  InputGestureCollection keyInputs =新InputGestureCollection(); 
keyInputs.Add(新KeyGesture(Key.OemComma,ModifierKeys.Control));
preferencesCommand =新RoutedUICommand(首选项...,首选项中的typeof(MyCommands),keyInputs);


解决方案

我觉得的KeyGesture构造带有一个显示字符串会的工作。你可以这样调用它:

  InputGestureCollection keyInputs =新InputGestureCollection(); 
keyInputs.Add(新KeyGesture(Key.OemComma,ModifierKeys.Control,按Ctrl +));
preferencesCommand =新RoutedUICommand(首选项...,首选项中的typeof(MyCommands),keyInputs);


Question

I would like to assign the keyboard shortcut Ctrl + , (control plus comma) to the "Preferences..." menu item. How do I do that?

There is a Key.OemComma in the Key enumeration. I have used Key.OemComma as shown in the code sample below. That works fine functionality-wise. But GUI-wise: the menu item is displayed as

  • Preferences (Ctrl+OemComma)

instead of

  • Preferences (Ctrl+,)

Sample Code

InputGestureCollection keyInputs = new InputGestureCollection();
keyInputs.Add(new KeyGesture(Key.OemComma, ModifierKeys.Control));
preferencesCommand = new RoutedUICommand("Preferences...", "Preferences", typeof(MyCommands), keyInputs);

解决方案

I think the KeyGesture constructor that takes a display string would work. You could call it like this:

InputGestureCollection keyInputs = new InputGestureCollection();
keyInputs.Add(new KeyGesture(Key.OemComma, ModifierKeys.Control, "Ctrl+,"));
preferencesCommand = new RoutedUICommand("Preferences...", "Preferences", typeof(MyCommands), keyInputs);

这篇关于如何分配按Ctrl +,(控制加逗号)作为键盘快捷方式WPF菜单项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆