This question already has an answer here:
这个问题在这里已有答案:
- Multiple KeyBinding like Visual Studio in WPF 2 answers
像WPF 2中的Visual Studio一样的多个KeyBinding回答
One can define a shortcut in WPF with
可以在WPF中定义快捷方式
<KeyBinding Key="N" Modifiers="Control" Command="local:CustomCommands.MyCommand"/>
Shortcut CTRL + N
is now defined.
现在定义了快捷键CTRL + N.
Question: Is it also possible to define a double-key shortcut like Visual Studio 2012 uses it?
问题:是否也可以定义一个双键快捷方式,如Visual Studio 2012使用它?
Example: CTRL + R, A
is used to execute all unit tests.
示例:CTRL + R,A用于执行所有单元测试。
1 个解决方案
#1
2
Use Gesture in conjunction with Key instead of modifier. As per MSDN:
将Gesture与Key结合使用而不是修饰符。根据MSDN:
When defining a KeyBinding in Extensible Application Markup Language (XAML) there are two ways to specify the KeyGesture. The first way to establish a KeyBinding in XAML is to define the Gesture attribute of the KeyBinding element, which enables a syntax to specify keys and modifiers as a single string, for example "CTRL+P". The second way is to define the Key attribute and the Modifiers attributes of the KeyBinding element.
在可扩展应用程序标记语言(XAML)中定义KeyBinding时,有两种方法可以指定KeyGesture。在XAML中建立KeyBinding的第一种方法是定义KeyBinding元素的Gesture属性,该属性允许语法将键和修饰符指定为单个字符串,例如“CTRL + P”。第二种方法是定义KeyBinding元素的Key属性和Modifiers属性。
<KeyBinding Gesture="Control+R" Key="A"
Command="local:CustomCommands.MyCommand"/>
This will execute MyCommand
in case Ctrl+R,A
combination is used.
如果使用Ctrl + R,则执行MyCommand,使用组合。
#1
2
Use Gesture in conjunction with Key instead of modifier. As per MSDN:
将Gesture与Key结合使用而不是修饰符。根据MSDN:
When defining a KeyBinding in Extensible Application Markup Language (XAML) there are two ways to specify the KeyGesture. The first way to establish a KeyBinding in XAML is to define the Gesture attribute of the KeyBinding element, which enables a syntax to specify keys and modifiers as a single string, for example "CTRL+P". The second way is to define the Key attribute and the Modifiers attributes of the KeyBinding element.
在可扩展应用程序标记语言(XAML)中定义KeyBinding时,有两种方法可以指定KeyGesture。在XAML中建立KeyBinding的第一种方法是定义KeyBinding元素的Gesture属性,该属性允许语法将键和修饰符指定为单个字符串,例如“CTRL + P”。第二种方法是定义KeyBinding元素的Key属性和Modifiers属性。
<KeyBinding Gesture="Control+R" Key="A"
Command="local:CustomCommands.MyCommand"/>
This will execute MyCommand
in case Ctrl+R,A
combination is used.
如果使用Ctrl + R,则执行MyCommand,使用组合。