C# 用户编程键绑定
注意,这是我的后续行动 我实现了一个包含键绑定的类以及一个允许用户更改键绑定的“表单”。这很有效-密钥绑定得到更新,并用于实现适当的命令。然而,这是非常乏味的,似乎效率低下。基本上,我已经为C# 用户编程键绑定,c#,wpf,key-bindings,C#,Wpf,Key Bindings,注意,这是我的后续行动 我实现了一个包含键绑定的类以及一个允许用户更改键绑定的“表单”。这很有效-密钥绑定得到更新,并用于实现适当的命令。然而,这是非常乏味的,似乎效率低下。基本上,我已经为键和修饰符创建了一个属性: private Key _changeBackgroundKey; /// <summary> /// Key to change the color of the background /// </summary> public Key ChangeBac
键
和修饰符
创建了一个属性:
private Key _changeBackgroundKey;
/// <summary>
/// Key to change the color of the background
/// </summary>
public Key ChangeBackgroundKey
{
get { return _changeBackgroundKey; }
set
{
if (_changeBackgroundKey == value)
return;
_changeBackgroundKey = value;
OnPropertyChange(nameof(ChangeBackgroundKey));
}
}
private ModifierKeys _changeBackgroundModifier;
/// <summary>
/// Key modifier to change the color of the background
/// </summary>
public ModifierKeys ChangeBackgroundModifier
{
get { return _changeBackgroundModifier; }
set
{
if (_changeBackgroundModifier == value)
return;
_changeBackgroundModifier = value;
OnPropertyChange(nameof(ChangeBackgroundModifier));
}
}
这是为我想要实现的每个键绑定完成的-我必须为键
和修改器键
创建一个属性,在XAML中绑定它们,并相应地更新逻辑。有没有更好/更有效的方法?虽然我的虚拟项目只使用了四个键绑定,但我的实际应用程序使用了更多
<KeyBinding Key="{Binding ChangeBackgroundKey}" Modifiers="{Binding ChangeBackgroundModifier}" Command="{Binding Settings.ChangeBackgroundColorCommand}"/>