MVVM - 中的PropertyChanged型号或视图模型? [英] MVVM - PropertyChanged in Model or ViewModel?

查看:207
本文介绍了MVVM - 中的PropertyChanged型号或视图模型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经通过一些MVVM教程过去了,我已经看到了这个工作是双向的。最常使用的视图模型为PropertyChanged的(这是我一直在做什么),但我碰到一个示范这样做出来。有两种方法可以接受吗?如果是这样,有什么好处/的不同方法的缺点?

I have gone through a few MVVM tutorials and I have seen this done both ways. Most use the ViewModel for PropertyChanged (which is what I have been doing), but I came across one that did this in the Model. Are both methods acceptable? If so, what are the benefits/drawbacks of the different methods?

推荐答案

INotifyPropertyChanged的(INPC)接口用于绑定

The INotifyPropertyChanged (INPC) interface is used for Binding.

所以,在一般情况下,你想实现它在你的视图模型

So, in the average case, you want to implement it in your ViewModel.

视图模型用于分离的模式查看,所以没有必要有INPC在模式,因为你不想让绑定你的模式

The ViewModel is used to decouple the Model from your View, so there is no need to have INPC in your Model, as you do not want Bindings to your Model.

在大多数情况下,即使是较小的特性,你仍然有一个非常小的视图模型

In most cases, even for smaller properties, you still have a very small ViewModel.

如果你想为 MVVM 了坚实的基础,你可能会使用某种MVVM框架喜欢的caliburn.micro 。使用它会给你一个 ViewModelBase (或在此 NotifyPropertyChangedBase ),这样就不必自己实现这些接口成员并且可以只用 NotifyOfPropertyChange(()=> myProperty的)。,这是方式更容易,更容易出错。

If you want a solid base for MVVM, you are probably going to use some kind of MVVM Framework like caliburn.micro. Using it will give you a ViewModelBase (or here NotifyPropertyChangedBase) so that you do not have to implement those interface members yourself and can just use NotifyOfPropertyChange(() => MyProperty), which is way easier and less error prone.

更新
作为似乎有许多Windows窗体开发人员在那里,这里是一个很好的
文章会给什么MVVM大约是更深层次的理解:
< A HREF =htt​​p://msdn.microsoft.com/en-us/magazine/dd419663.aspx#id0090102> MSDN杂志上MVVM

我已经挂尤其是关切的数据模型的一部分​​,该问题是关于

I have linked especially the part about the datamodel, that the question is about.

这篇关于MVVM - 中的PropertyChanged型号或视图模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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