0
点赞
收藏
分享

微信扫一扫

Silverlight + Model-View-ViewModel (MVVM)

(Data)Model-View-ViewModel模式跟经典的Model-View-Presenter模式很相似,除了你需要一个为View量身定制的model,这个model就是ViewModel。ViewModel包含所有由UI特定的接口和属性,它们是轻松构建UI的必要元素。View绑定到ViewModel,然后执行一些命令在向它请求一个动作。而反过来,ViewModel跟Model通讯,告诉它更新来响应UI。

     早在2005年,John Gossman写了一篇关于Model-View-ViewModel模式的博文,这种模式被他所在的微软的项目组用来创建Expression Blend(即'Sparkle')。它跟Martin Fowler的Presentation Model非常相似,唯一不同的是,它填平了presentation model和使用了WPF的丰富的数据绑定的view之间的沟壑。在Dan Crevier发表了神作DataModel-View-ViewModel series博文系列之后,(D)MVVM模式开始变得流行起来。

     (Data)Model-View-ViewModel模式跟经典的Model-View-Presenter模式很相似,除了你需要一个为View量身定制的model,这个model就是ViewModel。ViewModel包含所有由UI特定的接口和属性,它们是轻松构建UI的必要元素。View绑定到ViewModel,然后执行一些命令在向它请求一个动作。而反过来,ViewModel跟Model通讯,告诉它更新来响应UI。

      这使得为应用构建UI非常的容易。往一个应用程序上贴一个界面越容易,外观设计师就越容易使用Blend来创建一个漂亮的界面。同时,当UI和功能越来越松耦合的时候,功能的可测试性就越来越强。

​​John Gossman's Introduction to Model/View/ViewModel pattern for building WPF apps​​

John Gossman 2005年写的一篇关于Model-View-ViewModel模式的博文

StackOverflow 讨论 ​​Should I use the Model-View-ViewModel (MVVM) pattern in Silverlight projects?​​

  • ​​Jonas Follesø's YouCard example​​
  • ​​Nikhil Kothari's ViewModel Pattern in Silverlight​​​ and a funky ​​extension to MVVM using the DLR​​
  • ​​Martin Fowler's Presentation Model​​


​​WPF 应用程序使用程序的模型视图 ViewModel 设计模式​​

为什么 WPF 开发人员喜欢 MVVM

一旦开发人员成为熟悉 WPF 和 MVVM,很难区分这两者。 MVVM 是 WPF 开发人员的语言 franca,因为它是适合在 WPF 平台 WPF 为了方便地构建应用程序使用 MVVM 模式 (在其他)。 实际上,Microsoft 使用 MVVM 内部开发 WPF 应用程序,Microsoft Expression Blend,如,核心 WPF 平台时正在建设中。 WPF,如外观不控制模型和数据模板的许多方面使用显示的状态和行为的 MVVM 提升强的分离。

​​Dan Crevier's DataModel-View-ViewModel pattern series​​

8篇介绍WPF的 ​​sample DataModel​​​ 和 ​​ViewModel​​

​​David Wynn's Silverlight and the View-ViewModel Pattern​​

使用 ​​NInject​​​, ​​Silverlight Extensions (Command)​​​ 和​​Unit Testing​​的例子

Josh Smith讨论​​MVVM eliminates 99% of the need for ValueConverters​​

The only place I can see a use for value converters in an MVVM architecture is cross-element bindings. If I'm binding the Visibility of a panel to the IsChecked of a CheckBox, then I will need to use the BooleanToVisibilityConverter.

​​Mark Heath's Model View View-Model (MVVM) in Silverlight​​

在Silverlight 2.0演示MVVM 的例子



举报

相关推荐

0 条评论