简体   繁体   English

XAML键绑定1,2,3

[英]XAML KeyBinding 1,2,3

I decided to duplicate the buttons by pressing the keys on my page but getting an error like this: 我决定通过按页面上的键来复制按钮,但出现如下错误:

"1" can not be used as a value for "Key". 不能将“ 1”用作“键”的值。 Numbers are not valid enumeration values. 数字不是有效的枚举值。

 <Page.InputBindings>
    <KeyBinding Command="{Binding Btn_Click}" 
               CommandParameter="{Binding ElementName=btn1,Path=Content}"
                Key="1"/>
    <KeyBinding Command="{Binding Btn_Click}" 
               CommandParameter="{Binding ElementName=btn2,Path=Content}"
                Key="2"/>
    <KeyBinding Command="{Binding Btn_Click}" 
               CommandParameter="{Binding ElementName=btn3,Path=Content}"
                Key="3"/>
    <KeyBinding Command="{Binding Btn_Click}" 
               CommandParameter="{Binding ElementName=btn4,Path=Content}"
                Key="4"/>
</Page.InputBindings>

Can I deceive the system? 我可以欺骗系统吗?

You can use D1 , which is the enum value for the 1 key. 您可以使用D1 ,它是1键的枚举值。 See the Key Enumeration page for a list of all possible values. 有关所有可能值的列表,请参见“ 键枚举”页面。

<KeyBinding Command="{Binding SomeCommand}" Key="D1"/>

or just biniding: 或只是biniding:

<KeyBinding Command="{Binding SomeCommand}" Key="{Binding MyKey}"/>

VM: 虚拟机:

public Key MyKey
{
    get => Key.D1;
}

this is because you can't do enumerator like: 这是因为您不能像这样进行枚举:

enum MyEnum
{
    1,
    2,
    3
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM