在视图模型INotifyPropertyChanged的主场迎战的DependencyProperty [英] INotifyPropertyChanged vs. DependencyProperty in ViewModel

查看:166
本文介绍了在视图模型INotifyPropertyChanged的主场迎战的DependencyProperty的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在实施模型 - 视图 - 视图模型架构WPF应用程序的视图模型,似乎有两个主要的选择如何使它databindable。我已经看到了使用的DependencyProperty的观点是要对绑定的属性的实现和我所看到的视图模型实现INotifyPropertyChanged的替代。

When implementing the ViewModel in a Model-View-ViewModel architecture WPF application there seem to be two major choices how to make it databindable. I have seen implementations that use DependencyProperty for properties the View is going to bind against and I have seen the ViewModel implementing INotifyPropertyChanged instead.

我的问题是,当我要preFER一个比其他?是否有任何性能差异?难道真的是一个好主意,让视图模型依赖于WPF?做些什么我需要考虑做出设计决策是什么时候?

My question is when should I prefer one over the other? Are there any performance differences? Is it really a good idea to give the ViewModel dependencies to WPF? What else do I need to consider when make the design decision?

推荐答案

肯特写了一篇关于这个话题的有趣的博客:的视图模型:波苏斯与DependencyObjects

Kent wrote an interesting blog about this topic: View Models: POCOs versus DependencyObjects.

简短的摘要:


  1. DependencyObjects未标记为
    序列化

  2. 的DependencyObject的类覆盖和密封件的equals()和
    GetHash code()方法

  3. 系统的DependencyObject具有线程关联性 - 它只能访问
    线程在其上是
    创建

我preFER的POCO方法。为presentationModel(又名视图模型),它实现INotifyPropertyChanged接口的基类,可以在这里找到: HTTP://compositeextensions.$c$cplex .COM

I prefer the POCO approach. A base class for PresentationModel (aka ViewModel) which implements INotifyPropertyChanged interface can be found here: http://compositeextensions.codeplex.com

这篇关于在视图模型INotifyPropertyChanged的主场迎战的DependencyProperty的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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