无法使用 DialogResult
我尝试使用 DialogResult
来检查 Messagebox
的 YesNoCancel。我正在使用以下代码,我没有看到任何问题:
DialogResult dlgResult = MessageBox.Show(
"Save changes before closing?",
"Warning",
MessageBoxButton.YesNoCancel,
MessageBoxImage.Question);
但是 Visual Studio 向我抛出错误说
'System.Windows.Window.DialogResult' 是一个“属性”,但使用起来就像 '类型'
I tried to use DialogResult
to check an Messagebox
's YesNoCancel. I'm using the following code which I don't see any problem with:
DialogResult dlgResult = MessageBox.Show(
"Save changes before closing?",
"Warning",
MessageBoxButton.YesNoCancel,
MessageBoxImage.Question);
But Visual Studio throws me error saying
'System.Windows.Window.DialogResult'
is a 'property' but is used like a
'type'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
DialogResult 枚举 和窗口.DialogResult 属性。
要解决此问题,可以使用枚举的完全限定名称。如下所示:
但是,由于您使用的是WPF,因此请使用MessageBoxResult Enumeration 来获取消息的结果:
There is a confliction here between the DialogResult Enumeration and the Window.DialogResult Property.
To solve this problem, you can use the fully qualified name of the enumuration. As the following:
However, since you are using WPF, use MessageBoxResult Enumeration to get the result of the message:
问题是
DialogResult
也是表单的一个属性,编译器认为您正在引用此属性。这里有多种选择:
System.Windows.Forms.DialogResult
var
让编译器找出类型并摆脱名称冲突The problem is
DialogResult
is also a property of the form and the compiler thinks you are refering to this property.You have several choices here:
System.Windows.Forms.DialogResult
var
to let the compiler figure out the type and get rid of the name collisionDialogResult
不是一种类型,它是一个属性,您想要类型MessageBoxResult
我可以从您没有使用 winforms 的问题中看出。所以代码会这样读:
DialogResult
is not a type, its a property, you want the typeMessageBoxResult
I can see from the question you are not using winforms. So the code would read,
尝试将
dlgResult
声明为var
。然后它应该可以工作WPF下的
MessageBox.Show
确实返回MessageBoxResult 而不是DialogResult
。DialogResult
用于WindowsForms。Try to declare
dlgResult
asvar
. Then it should workAlso
MessageBox.Show
under WPF does return MessageBoxResult and notDialogResult
.DialogResult
is used in WindowsForms.只需尝试使用 MessageBoxResult
MessageBox 将返回 MessageBoxResult 枚举值
just try with MessageBoxResult
MessageBox will return MessageBoxResult enum values
然后使用结果来检查
then use result to check