Reputation: 39
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". 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?
Upvotes: 2
Views: 1594
Reputation: 1049
You can use D1
, which is the enum value for the 1
key. See the Key Enumeration page for a list of all possible values.
<KeyBinding Command="{Binding SomeCommand}" Key="D1"/>
or just 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
};
Upvotes: 7