另一个"ViewModel关闭视图"问题... [英] Another 'ViewModel closes the View' question...

查看:67
本文介绍了另一个"ViewModel关闭视图"问题...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正处于学习曲线的中间,这是通向MVVM乌托邦的路!
我的问题确实涉及从视图模型关闭视图的能力.

我不想强迫解决方案适应某种模式,但MVVM在所有其他领域都非常适合,所以只剩下一点需要解决.

我正在从事的项目正在使用与Microsoft Outlook类似的系统.
您有一个包含所有内容的主视图(窗口).
这些内容可能是Outlook中的消息或联系人.
视图中,您可以选择创建一个新对象或打开一个现有的对象.
无论您选择哪个选项,都会打开一个新视图(窗口),为您提供一个用于编辑的表单.

从现在开始,每个打开的新视图都具有以下选项(与我的问题有关)...
1,保存.
2,关闭.
3,保存并保存;关闭.

保存非常简单,只是视图模型上的一个属性,该属性返回一个ICommand(RelayCommand/DelegateCommand).
关闭也非常简单,这就是右上角的叉号窗口的手角.
保存并保存但是,关闭是不同的.对于选项2,关闭实际上只是Windows的一部分,我们没有编写任何代码来执行此操作.
那么我将如何实现选项3?

非常感谢

I'm somewhere in the middle of the learning curve that is the path to MVVM utopia!
My question really concerns the ability to close a view from a view model.

I don't want to be guilty of trying to force a solution to fit a pattern, but MVVM fits so well in all other areas there's just this one bit left to figure out.

The project I'm working on is a system analagous to Microsoft Outlook.
You have a main view (window) which has a list of things.
These things could be messages or contacts in Outlook.
From the main view you have the option to create a new thing or open an existing one.
Regardless of which option you choose, a new view (window) opens to present you with a form for editing.

From this point on, each new view that opens has the following options (relevant to my question)...
1, Save.
2, Close.
3, Save & Close.

Save is pretty straightforward, is just a property on the viewmodel which returns an ICommand (RelayCommand/DelegateCommand).
Close is also pretty straightforward, that's just the cross in the top right hand corner of the window.
Save & Close, however, is different. With option 2, the close is actually just a part of windows, we're not writing any code to do this.
So how would I go about implementing option 3? Where the viewmodel first needs to persist the changes and then needs to close the view?

Many thanks,

推荐答案

您好,MQCA,

您可以创建一个SaveAndClose命令,在execute方法中结合了保存数据和删除视图的逻辑.

最好的问候,
智欣

Hi MQCA,

You can create a SaveAndClose command, in the execute method combines the logic of saving data and removing view.

Best Regards,
Zhi-Xin


这篇关于另一个"ViewModel关闭视图"问题...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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