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

后端 未结 3 1905
-上瘾入骨i
-上瘾入骨i 2021-02-18 15:20

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 en

3条回答
  •  梦毁少年i
    2021-02-18 15:35

    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.

提交回复
热议问题