Multiple KeyBinding like Visual Studio in WPF

拟墨画扇 提交于 2019-12-01 20:20:27

问题


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

I have found this article on on blogspot regarding Multiple Keybinding but it makes multiple gesture like Ctrl + A,B

Is it possible to make a Keybinding that flexible like (VS Studio) through XAML Syantax.


回答1:


Sequence key combo's like VS has are not natively part of WPF and most other UI frameworks. 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.




回答2:


    <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.

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



来源:https://stackoverflow.com/questions/7683301/multiple-keybinding-like-visual-studio-in-wpf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!