WPF:如何显示带有确认的设置对话框/页面? [英] WPF : How do I display a setting dialog/page with confirmation?

查看:279
本文介绍了WPF:如何显示带有确认的设置对话框/页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用Windows窗体时,我通常创建一个Windows对话框并读取对话框结果以查看下一步.例如:

When working with windows form, I usually create a windows dialog and read the dialog result to see what to do next. e.g:

SettingsDlg setting = new SettingsDlg();
if(setting.ShowDialog() == DialogResult.OK)
{
//do something
}
else
{
//do something else
}



如何使用WPF完成相同的任务?我正在使用MVVM Toolkit,因此我后面的xaml代码基本上是空的,我希望这样.大部分逻辑都在我的ViewModel类中.



How do I achieve the same task using WPF? I''m using MVVM Toolkit, so my xaml code behind is basically empty and I''d like it to be that way. Most of the logic is in my ViewModel classes.

推荐答案

以非常相似的方式:System.Windows.Window.ShowDialog,请参见:
http://msdn.microsoft.com/en-us/library/system. windows.window.showdialog.aspx [ ^ ].

您可能对对话结果感兴趣吗?由于结果是布尔型可为空的类型,因此只有三个选项:true,false和null.

有关详细信息,请参见:
http://msdn.microsoft.com/en-us/library/system. windows.window.dialogresult.aspx [ ^ ].

如果您需要更多详细信息(例如按下了什么按钮"),该怎么办?很简单:您将必须自己开发此代码(然后考虑一下,这比System.Windows.Forms中的要好).创建窗口的某些属性(枚举类型或其他属性),内部或公共使用只读属性,私有使用读写属性.窗口的控件(如按钮)应为该属性分配值,并且在关闭对话框时,调用方方法将读取该属性的值.

—SA
In a very similar way: System.Windows.Window.ShowDialog, please see:
http://msdn.microsoft.com/en-us/library/system.windows.window.showdialog.aspx[^].

Probably you are interested in dialog results? As the result is the Boolean nullable type, there are only three options: true, false and null.

For the detail, please see:
http://msdn.microsoft.com/en-us/library/system.windows.window.dialogresult.aspx[^].

What to do if you need more detail (like "what button was pressed")? Simple: you will have to develop this code by yourself (and come to think about, this is better than in System.Windows.Forms). Create some property (of enumeration type or whatever) of the window, read-only for internal or public use, read-write for private. The controls of the window (like buttons) should assign values to this property, and the caller method will read the value of the property when the dialog is closed.

—SA


这篇关于WPF:如何显示带有确认的设置对话框/页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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