gpt4 book ai didi

wpf - WPF中的多键手势

转载 作者:行者123 更新时间:2023-12-02 15:08:46 26 4
gpt4 key购买 nike

我有一个名为Comment SelectionRoatedUICommand。我需要为此命令添加一个输入手势,就像在 VIsual Studio 中一样,即。 (Ctrl+KCtrl+C)。我怎样才能做到这一点?请帮助我。 (记住 VS 功能)。

问候,贾瓦哈

最佳答案

此代码是为“Ctrl+W、Ctrl+E”和/或“Ctrl+W、E”组合编写的,但是您可以针对任何组合键对其进行参数化:

XAML:

<MenuItem Header="Header" InputGestureText="Ctrl+W, E" Command="ShowCommand"/>

C#:

public static readonly RoutedUICommand ShowCommand = new RoutedUICommand(
"Show command text",
"Show command desc",
typeof(ThisWindow),
new InputGestureCollection(new[] { new ShowCommandGesture (Key.E) }));

public class ShowCommandGesture : InputGesture
{
private readonly Key _key;
private bool _gotFirstGesture;
private readonly InputGesture _ctrlWGesture = new KeyGesture(Key.W, ModifierKeys.Control);

public ShowCommandGesture(Key key)
{
_key = key;
}

public override bool Matches(object obj, InputEventArgs inputEventArgs)
{
KeyEventArgs keyArgs = inputEventArgs as KeyEventArgs;
if (keyArgs == null || keyArgs.IsRepeat)
return false;

if (_gotFirstGesture)
{
_gotFirstGesture = false;

if (keyArgs.Key == _key)
{
inputEventArgs.Handled = true;
}

return keyArgs.Key == _key;
}
else
{
_gotFirstGesture = _ctrlWGesture.Matches(null, inputEventArgs);
if (_gotFirstGesture)
{
inputEventArgs.Handled = true;
}

return false;
}
}
}

关于wpf - WPF中的多键手势,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2181991/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com