【问题标题】:Multiple Keys in KeyBinding?KeyBinding中的多个键?
【发布时间】:2015-02-12 16:49:51
【问题描述】:

我想在我的 Wpf 应用程序中设置热键。 在简单的情况下使用 KeyBindings 有效,例如:Ctrl+BCtrl+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


【解决方案1】:

正如我所说,有一个实现可以覆盖多个键的 KeyBinding 和 Gestures。请参阅以下链接。他重写了 InputGesture 的实现来实现这个多键绑定。 http://kent-boogaart.com/blog/multikeygesture

【讨论】:

  • 修改了我的答案,试试看。
  • 我以前试过这个。如果我输入Ctrl+C+B,它将被触发;如果我输入Ctrl+D+B,它将再次被触发,如果我输入Ctrl+B,它将被触发。
  • 我认为我们可能需要重写 KeyBinding 类来接受多个键。
猜你喜欢
  • 1970-01-01
  • 2011-05-02
  • 1970-01-01
  • 1970-01-01
  • 2012-07-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多