简体   繁体   English

多个KeyBinding,如WPF中的Visual Studio

[英]Multiple KeyBinding like Visual Studio in WPF

I have tried to read many posts on StackOverflow about how to implement the KeyBinding like Visual Studio Ctrl+Shift+ A or Ctrl+K,Ctrl+C but no luck 我试图在StackOverflow上阅读很多关于如何实现KeyBinding的帖子,如Visual Studio Ctrl + Shift + ACtrl + K,Ctrl + C但没有运气

I have found this article on on blogspot regarding Multiple Keybinding but it makes multiple gesture like Ctrl + A,B 我在blogspot上发现了关于多键绑定的这篇文章,但是它做了多个手势,比如Ctrl + A,B

Is it possible to make a Keybinding that flexible like (VS Studio) through XAML Syantax. 是否可以通过XAML Syantax使(VS Studio)具有灵活性的Keybinding。

Sequence key combo's like VS has are not natively part of WPF and most other UI frameworks. VS之类的序列键组合本身不是WPF和大多数其他UI框架的一部分。 The reason being that such combos hail from text editors of the Jurassic era and survive only in a few modern contexts where users of said era still survive and even thrive. 原因在于,这种组合来自侏罗纪时代的文本编辑,并且只能在少数现代环境中生存,在这些环境中,所述时代的用户仍然存活甚至茁壮成长。 ;-) ;-)

You should be able to provide your own handling mechanisms for this in a fairly straight forward manner: 您应该能够以相当直接的方式为此提供自己的处理机制:

  • Build a mechanism to parse and represent these combos. 构建一个解析和表示这些组合的机制。
  • Provide key handling logic that recognizes the beginning of the sequence and goes into compound key mode 提供识别序列开始并进入复合键模式的键处理逻辑
  • Provide a cue to the user when in combo mode 在组合模式下为用户提供提示
  • Adapt your key handling when in combo mode 在组合模式下调整您的键处理

Ideally you'll associate these combos command so there is no disparity between singles and combos. 理想情况下,您将关联这些组合命令,以便单打和组合之间没有差异。

    <KeyBinding x:Name="mykeybinding" Gesture="CTRL+E" Key="P" 
                Command="commandname"/>

Seems to be working ok for me you have to press ctrl+E+P to execute command. 似乎对我有用,你必须按ctrl + E + P执行命令。

Based on http://msdn.microsoft.com/en-in/library/system.windows.input.keybinding.aspx 基于http://msdn.microsoft.com/en-in/library/system.windows.input.keybinding.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM