Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 用户编程键绑定_C#_Wpf_Key Bindings - Fatal编程技术网

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}"/>