在 WPF 窗口中按 Enter 键登录。

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21361525/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 10:36:29  来源:igfitidea点击:

Pressing Enter Key to Login in WPF windows.

c#wpfwinformsvisual-studio-2010user-interface

提问by Gawjus Gurl

I know that assigning the button to the AcceptButton property in a form would allow me to submit the form in Windows Forms. The problem I'm having is that I'm using a WPF Window as the login screen and I don't know how to make the button work when the Enter Key is pressed. There isn't an AcceptButton Property for WPF Windows. Any Help?

我知道将按钮分配给表单中的 AcceptButton 属性将允许我在 Windows 窗体中提交表单。我遇到的问题是我使用 WPF 窗口作为登录屏幕,但我不知道如何在按下 Enter 键时使按钮工作。WPF Windows 没有 AcceptButton 属性。任何帮助?

回答by Rohit Vats

Set IsDefaultto True.

IsDefault设置为True.

<Button IsDefault="True"/>

From MSDN:

MSDN

Gets or sets a value that indicates whether a Button is the default button. A user invokes the default button by pressing the ENTER key.

获取或设置一个值,该值指示 Button 是否为默认按钮。用户通过按 ENTER 键调用默认按钮。