为什么 DialogResult 在 WPF 中是一个可为空的布尔值? [英] Why is DialogResult a nullable bool in WPF?

查看:37
本文介绍了为什么 DialogResult 在 WPF 中是一个可为空的布尔值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于对话的结果是 WPF 中可为空的布尔值这一事实,谁能想到一个很好的解释?这一直让我感到困惑.在 WinForms 中,它是一个枚举类型,这对我来说更有意义.

Can anyone think of a good explanation for the fact that result of a dialog is a nullable bool in WPF? This has always baffled me. In WinForms it was an enum type and that made a lot more sense to me.

推荐答案

在我看来,这样做是因为在大多数情况下,您不需要像 Retry 或 Ignore 这样的通用专用选项.

In my opinion this was done because in most cases you don't need the generalized specialized options like Retry or Ignore.

如果您需要的不仅仅是确定/取消,您应该使用某种任务对话框,例如有书面答案.这样,您就不仅限于几十年前有人想到的少数枚举值,而且 DialogResult 只是基本使用的正/负,您可以实现自己的特定于您的高级需求的属性.因此只需要 true/false,null 表示窗口还没有关闭(还没有给属性赋值).

If you need more than OK/Cancel, you are supposed to use some kind of task dialog, e.g. with written-out answers. That way, you're not limited to the few enum values someone thought of some decades ago, and the DialogResult is just positive/negative for basic use and you can implement your own property that is specific to your advanced needs. Therefore only true/false is needed, and null indicating that the window has not been closed yet (no value has been assigned to the property yet).

如果您的对话框不仅仅是用户应该回答的问题(例如输入表单),通常最好使用确定"/取消",这样您就不需要更多值.

If you have a dialog that is more than just a question the user should answer (e.g. an entry form), you're typically better off with OK/Cancel, so you don't need more values.

这篇关于为什么 DialogResult 在 WPF 中是一个可为空的布尔值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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