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

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

问题描述

我创建一个WPF对话框。这就像我们正常的MessageBox 确定取消按钮。所以在打开的对话框当选择了确定按钮如何创建这样一个对话框?

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?

推荐答案

要设置窗口的默认按钮

设置默认按钮的的IsDefault财产为true。

Set your default button's IsDefault property to true.

请注意,您还可以通过设置按钮的 IsCancel财产为true。

Note that you can also set a Window's Cancel button by setting a button's IsCancel property to true.

设置所选(聚焦)按钮,在窗口

如果你想选择一个特定的按钮,然后用这样的对焦方式:

If you want to select a particular button then use the Focus method like this:

yourButton.Focus();

您可以这样做,当窗口负载(在Window_Loaded事件)。

You might do this when a Window loads (in the Window_Loaded event).

要当你打开的窗户确保它的 IsTabStop属性设置为true,并保证其的 TabIndex属性是比在窗口中的任何其他控制低。

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天全站免登陆