如何在wpf对话框中选择默认按钮? [英] How to select default button in wpf dialog?

查看:328
本文介绍了如何在wpf对话框中选择默认按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个WPF对话框。这就像我们正常的 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆