Reputation: 21
<Window.InputBindings>
<KeyBinding Key="0" Command="{Binding ZeroCommand}"/>
<KeyBinding Key="1" Command="{Binding OneCommand}"/>
<KeyBinding Key="2" Command="{Binding TwoCommand}"/>
<KeyBinding Key="3" Command="{Binding ThreeCommand}"/>
<KeyBinding Key="4" Command="{Binding FourCommand}"/>
<KeyBinding Key="5" Command="{Binding FiveCommand}"/>
<KeyBinding Key="6" Command="{Binding SixCommand}"/>
<KeyBinding Key="7" Command="{Binding SevenCommand}"/>
<KeyBinding Key="8" Command="{Binding EightCommand}"/>
<KeyBinding Key="9" Command="{Binding NienCommand}"/>
<KeyBinding Key="OemPlus" Command="{Binding PlusCommand}"/>
<KeyBinding Key="OemMinus" Command="{Binding MinusCommand}"/>
<KeyBinding Key="OemBackslash" Command="{Binding DevideCommand}"/>
<KeyBinding Key="Multiply" Command="{Binding MultiplyCommand}"/>
<KeyBinding Key="Return" Command="{Binding EqualsCommand}"/>
</Window.InputBindings>
I was creating a basic calculator app when I ran into this issue. I am getting a compilation error '0' can not be used as a value for 'Key'. Numbers are not valid enumeration values. In fact OemMinus is the only command that is being bound.
I think could fix this by creating a InputBindingConfiguration class with a singleton, define the keys there and bind to those keys but I was wondering if there was a way of doing this purely in Xaml ?
Upvotes: 1
Views: 3157
Reputation: 1964
check the proper key binding below Link : WPFKeyBindings
Basic Keys
Key - Code Key(s)
A - Z The basic letter keys.
D0 - D9 The numeric keys from the main section of the keyboard. Space The space bar.
F1 - F24 The function keys.
Upvotes: 1