Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the Best Way to Catch the Return Key in a PasswordBox? (WPF/XAML)

Tags:

What's the best way to catch the return key in a PasswordBox? (WPF/XAML)

I have a TextBox field and a PasswordBox field on my login form (for username and password entry). I also have a login button which invokes the method that performs the login validation process.

I need to make the Return key react the same way in the PasswordBox, so that the user can have the option enter their username and password and simply hit Return to log in.

Does anyone know how this is done in WPF? Any help is appreciated.

like image 853
Giffyguy Avatar asked Jul 24 '09 19:07

Giffyguy


1 Answers

There is an even easier mechanism to activate the button's code. WPF Button class provides a property called IsDefault. When set to true, if you press return while some objects in the window have focus, the code of the click event of the button will be fired automatically. This mechanism works like a charm with the passwordbox.

like image 68
Carlos G. Avatar answered Sep 18 '22 14:09

Carlos G.