WPF MVVM模式总结

发展历程:MVC -> MVP -> MV VM

MVP:

[WPF初学]基于WPF框架的MVVM模式简介 - lvan - lvan GoGo 的世界

MVVM:

[WPF初学]基于WPF框架的MVVM模式简介 - lvan - lvan GoGo 的世界

 WPF 入门

一篇很好的文章:

原文地址:http://www.codeproject.com/Articles/165368/WPF-MVVM-Quick-Start-Tutorial 《迅速开始了解WPF》

译文地址:http://www.cnblogs.com/xiaobaihome/archive/2011/11/28/2266536.html 

MVVM 框架比较

原文地址:http://blog.csdn.net/lu_yongchao/article/details/7291674

          Prism :CodeProject:http://www.codeproject.com/Articles/48287/Getting-Started-with-Prism-2-1-for-WPF Prism2.1实践(目前是4.1)

MVVM 逻辑层次

(1) 组成部分Model、View、ViewModel

(a)  View:UI界面

(b) ViewModel:它是View的抽象,负责View与Model之间信息转换,将View的Command传送到Model;

(c)     Model:数据访问层

 (2)  View与ViewModule连接:

(a)     Binding Data:实现数据的传递

(b)      Command:实现操作的调用

(c)      AttachBehavior:实现控件加载过程中的操作

MVVM具体应用

(1)     Command工作流程:

主要使用Prism的DelegeCommand、CompositeCommand类与订阅、发布原理。

(a)       ViewModel初始化命令(ICommand)

public DelegateCommand<object> AddAdministorCommand { get; private set; }

this.AddAdministorCommand = new DelegateCommand<object>(this.AddAdministor);

(b)     View UI元素绑定ViewModel Command属性

Command="{Binding Path=AddAdministorCommand}"

(c)     在ViewModel中定义一个事件(event),实现CompositePresentationEvent<object>接口(object-传递参数)。

public class AdministorRequestEvent: CompositePresentationEvent<AdministorViewModel>

{ }

(d)     使用TheAggregator订阅一个事件的执行者(Action)

this.TheAggregator.GetEvent<AdministorRequestEvent>().Subscribe(ShowAdministorVie        w);

        public void ShowAdministorView(AdministorViewModel administorVM)

{

            AdministorView administorV = new AdministorView();

            administorV.ViewDataContext = administorVM;

            administorV.Show();

           }

(e)    使用发布一个事件

private void AddAdministor(object obj)

{

this.TheAggregator.GetEvent<AdministorRequestEvent>().Publish( new AdministorViewModel(Administor.CreateNewAdministor(),_administorRepository));

}

 
 MVVM TreeView(剥离UI元素)
原文地址:http://www.cnblogs.com/leptonation/archive/2012/09/26/2704895.html
 
标签
原文地址:https://www.cnblogs.com/cuiyansong/p/MVVM.html