wpf 带有 IsDefault 和 IsDefaulted 的按钮有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18578969/
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
What's the difference between a button with IsDefault and IsDefaulted?
提问by alansiqueira27
Can anyone explain me better?
谁能更好地解释我?
I didn't understand too much just reading the documentation.
我只是阅读文档并不太明白。
采纳答案by Nitin
If you set IsDefaultto true, button will become the default button for the window i.e. if ENTER key is pressed when the current focus is not on any focusable control that accepts ENTER Key the button click event will be triggerred. If button click event can be triggered due to this default action then IsDefaultedwill be true else it will be false. That means if the Default button has focus in this case IsDefaultedwill be false as event will not be triggered by default.
如果设置IsDefault为 true,则按钮将成为窗口的默认按钮,即如果当前焦点不在任何接受 ENTER 键的可聚焦控件上时按下 ENTER 键,则将触发按钮单击事件。如果由于此默认操作可以触发按钮单击事件,则为IsDefaultedtrue,否则为 false。这意味着如果默认按钮在这种情况下具有焦点IsDefaulted将是假的,因为默认情况下不会触发事件。
IsDefaultedis readonly property which only tells if the button can be clicked by default at present state of focus i.e. the button click event can be triggered on ENTER press when Button did not has the focus. IsDefault we can set to true if we want that button should have this default behaviour i.e. when ENTER key is pressed and even button was not in focus button click should be triggered. We set IsDefault. IsDefault once set to true will remain true but IsDefaulted will change its value depending on which control currently has focus.
IsDefaulted是只读属性,它仅说明在当前焦点状态下默认情况下是否可以单击按钮,即当按钮没有焦点时,可以在按下 ENTER 键时触发按钮单击事件。IsDefault 我们可以设置为 true 如果我们希望该按钮应该具有此默认行为,即当按下 ENTER 键并且即使按钮不在焦点上时也应该触发按钮单击。我们设置 IsDefault。IsDefault 一旦设置为 true 将保持为 true,但 IsDefaulted 将根据当前具有焦点的控件更改其值。
回答by Reed Copsey
IsDefaultdetermines whether the button is the "default" button for the Window. IsDefaultedwill be trueif IsDefaultis true andthe current control with focus doesn't accept an ENTER keypress.
IsDefault确定按钮是否是窗口的“默认”按钮。 IsDefaulted将是true如果IsDefault为真并且当前具有焦点的控件不接受 ENTER 按键。
In general, if IsDefaultedis true, it means pressing enter will trigger that button at that point in time.
通常,如果IsDefaulted为 true,则表示按下 Enter 键将在该时间点触发该按钮。

