Fork me on GitHub

Silverlight + Model-View-ViewModel (MVVM)

     早在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 DataModelViewModel
    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 的例子


    相关文章:
    Hands-On Model-View-ViewModel (MVVM) for Silverlight and WPF :
     http://weblogs.asp.net/craigshoemaker/archive/2009/02/26/hands-on-model-view-viewmodel-mvvm-for-silverlight-and-wpf.aspx
    MVVM pattern in Silverlight using SLEextensions
    http://blog.developers.ba/post/2009/02/15/MVVM-pattern-in-Silverlight-using-SLEextensions.aspx
    [WPF] Another sample of WPF application using the pattern MVVM
    http://weblogs.asp.net/thomaslebrun/archive/2009/03/17/wpf-another-sample-of-wpf-application-using-the-pattern-mvvm.aspx

    浅谈MVP与Model-View-ViewModel(MVVM)设计模式

    http://mvvmref.codeplex.com/

    posted @ 2009-03-01 11:51  张善友  阅读(7733)  评论(1编辑  收藏  举报