Enter a key question

I am currently making a calculator application for my .NET class. The calculator works great when I use buttons. But when I use the keys on the keyboard, it does not work so well. For example, when I press the Enter key, I want the calculator to calculate the problem in the text box. Instead, click the button I last clicked, which causes problems. How can I prevent this?

I know this strange explanation, but I do not know how to explain it better.

+5
source share
1 answer

At the root level of your window / user control, add an InputBinding for the return keystroke. This will intercept the keystroke and execute your command as if you had pressed a button (assuming the Command property is also bound to this command).

Example with UserControl:

 <UserControl.InputBindings> <KeyBinding Key="Return" Command="{Binding EvaluateCommand}"/> </UserControl.InputBindings> 
+1
source

All Articles