在 MVVM 中,ViewModel 或 Model 应该实现 INotifyPropertyChanged 吗? [英] In MVVM should the ViewModel or Model implement INotifyPropertyChanged?

查看:29
本文介绍了在 MVVM 中,ViewModel 或 Model 应该实现 INotifyPropertyChanged 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用过的大多数 MVVM 示例都有 Model 实现 INotifyPropertyChanged,但在 Josh Smith 的 CommandSink 示例 ViewModel 实现了 INotifyPropertyChanged.

Most MVVM examples I have worked through have had the Model implement INotifyPropertyChanged, but in Josh Smith's CommandSink example the ViewModel implements INotifyPropertyChanged.

我仍然在认知上将 MVVM 概念放在一起,所以我不知道:

I'm still cognitively putting together the MVVM concepts, so I don't know if:

  • 您必须将 INotifyPropertyChanged 放在 ViewModel 中才能使 CommandSink 工作
  • 这只是一种反常现象,并不重要
  • 您应该始终让模型实现 INotifyPropertyChanged,这只是一个错误,如果将其从代码示例开发为应用程序,则会得到纠正
  • You have to put the INotifyPropertyChanged in the ViewModel to get CommandSink to work
  • This is just an aberration of the norm and it doesn't really matter
  • You should always have the Model implement INotifyPropertyChanged and this is just a mistake which would be corrected if this were developed from a code example to an application

其他人对您参与的 MVVM 项目有何经验?

What have been others' experiences on MVVM projects you have worked on?

推荐答案

我说的恰恰相反,我总是把我的 INotifyPropertyChanged 放在我的 ViewModel 上——你真的不想被污染您的模型具有相当 WPF 特定的功能,例如 INotifyPropertyChanged,这些东西应该放在 ViewModel 中.

I'd say quite the opposite, I always put my INotifyPropertyChanged on my ViewModel - you really don't want to be polluting your model with a fairly WPF specific feature like INotifyPropertyChanged, that stuff should sit in the ViewModel.

我相信其他人会不同意,但这就是我的工作方式.

I'm sure others would disagree, but that's the way I work.

这篇关于在 MVVM 中,ViewModel 或 Model 应该实现 INotifyPropertyChanged 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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