我可以创建在WPF键序列的键绑定? [英] Can I create a KeyBinding for a sequence of keys in WPF?
问题描述
是否有可能在WPF定义键绑定关键presses像在Visual Studio例如快捷键序列<大骨节病>控制骨节病> + <大骨节病>研究骨节病>,<大骨节病>控制骨节病> + <大骨节病> A 骨节病>运行在当前解决方案中的所有测试
Is it possible to define key bindings in WPF for a sequence of key presses like the shortcuts in Visual Studio e.g. Ctrl + R, Ctrl + A is run all tests in current solution
据我可以看到我只能绑定如单组合键<大骨节病>控制骨节病> + <大骨节病>取值骨节病>使用元素。我可以绑定使用此序列或我将不得不手动处理的关键presses做到这一点?
As far as I can see I can only bind single key combinations like Ctrl + S using the element. Can I bind sequences using this or will I have to manually handle the key presses to do this?
推荐答案
您需要创建自己的 InputGesture
,通过重写的 匹配
方法。
You need to create your own InputGesture
, by overriding the Matches
method.
类似的东西:
public class MultiInputGesture : InputGesture
{
public MultiInputGesture()
{
Gestures = new InputGestureCollection();
}
public InputGestureCollection Gestures { get; private set; }
private int _currentMatchIndex = 0;
public override bool Matches(object targetElement, InputEventArgs inputEventArgs)
{
if (_currentMatchIndex < Gestures.Count)
{
if (Gestures[_currentMatchIndex].Matches(targetElement, inputEventArgs))
{
_currentMatchIndex++;
return (_currentMatchIndex == Gestures.Count);
}
}
_currentMatchIndex = 0;
return false;
}
}
这可能需要不止一点点,就像忽略某些事件(如的KeyUp
的KeyDown
之间的事件事件不该T重置 _currentMatchIndex
),但你得到的图片...
It probably needs a little more than that, like ignoring certain events (e.g. KeyUp
events between KeyDown
events shouldn't reset _currentMatchIndex
), but you get the picture...
这篇关于我可以创建在WPF键序列的键绑定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!