Programmer Chick
Programmer Chick

Reputation: 31

WPF Bind button to key pressed

I have not done WPF development before.

I am creating a calculator. I want the "one" button to be bound to the keyboard key "1". So the click function of my button must execute when the keyboard key "1" is pressed.

Please advise on how to do this>

Upvotes: 2

Views: 6950

Answers (1)

Nahum
Nahum

Reputation: 7197

use this:

http://msdn.microsoft.com/en-us/library/system.windows.input.keygesture.aspx

<Window.InputBindings>
  <KeyBinding Command="{Binding MyCommand}"
              Gesture="CTRL+R" />
</Window.InputBindings>

Upvotes: 3

Related Questions