如何在wpf对话框中选择默认按钮? [英] How to select default button in wpf dialog?
问题描述
与 ok
和取消
按钮。如何创建这样的对话框,以便在打开对话框时选择 Ok
按钮?解决方案 设置窗口的默认按钮
设置默认按钮的 IsDefault属性为true。
<请注意,您还可以通过设置按钮的 IsCancel属性为true。
要设置窗口中的按钮
如果要选择特定的按钮,请使用Focus方法,如下所示:
yourButton.Focus();
您可以在Window加载(在Window_Loaded事件中)时执行此操作。
要在窗口打开时选择特定按钮,请确保其 IsTabStop属性设置为true,并确保其 TabIndex属性低于窗口上的任何其他控件。
I am creating a WPF dialog. It is like our normal messagebox
with ok
and cancel
button. How to create such a dialog so that the Ok
button is selected when the dialog is opened?
解决方案 To set a Window's Default button
Set your default button's IsDefault property to true.
Note that you can also set a Window's Cancel button by setting a button's IsCancel property to true.
To set the Selected (focused) button in a Window
If you want to select a particular button then use the Focus method like this:
yourButton.Focus();
You might do this when a Window loads (in the Window_Loaded event).
To select a particular button when your Window opens make sure its IsTabStop property is set to true and ensure its TabIndex property is lower than any other control on the Window.
这篇关于如何在wpf对话框中选择默认按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!