【发布时间】:2015-02-12 16:49:51
【问题描述】:
我想在我的 Wpf 应用程序中设置热键。 在简单的情况下使用 KeyBindings 有效,例如:Ctrl+B、Ctrl+A 等
<KeyBinding Gesture="Ctrl+B" Command="{Binding Source={StaticResource localCusomCommands}, Path=AddTTRowCommand}" ></KeyBinding>
<KeyBinding Modifiers="Control" Key="B" Command="{Binding Source={StaticResource localCusomCommands}, Path=AddTTRowCommand}" ></KeyBinding>
但如果我需要多个键的热键 Ctrl+P+B, Ctrl+ A+B等
<KeyBinding Modifiers="Control" Key="P,B" Command="{Binding Source={StaticResource localCusomCommands}, Path=AddTTRowCommand}" ></KeyBinding>
不工作。
<KeyBinding Gesture="Ctrl+B+A" Command="{Binding Source={StaticResource localCusomCommands}, Path=AddTTRowCommand}" ></KeyBinding>
不要编译。 Error 15 Unrecognized ModifierKeys 'B'.
如何做到这一点?
【问题讨论】:
-
你不能像那样绑定多个组合键,只能绑定多个修饰符和一个(单个)键。您必须深入到更低的级别并直接处理键盘/输入信号(或找到执行此操作的库)。
标签: wpf binding keyboard-shortcuts key-bindings