wpf 我应该使用什么 MVVM 框架?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1409553/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What framework for MVVM should I use?
提问by Rangel
I am developing an application with the MVVM model, but I have reached a point where I need to choose which framework to use.
我正在使用 MVVM 模型开发应用程序,但我已经到了需要选择要使用的框架的地步。
Among the possible options are:
可能的选项包括:
- MVVM Toolkit
- MVVM Foundation
- WPF Application Framework (WAF)
- Light MVVM
- Caliburn
- Cinch
- Prism
- ReactiveUI
- MVVM 工具包
- MVVM 基金会
- WPF 应用程序框架 (WAF)
- 轻量级MVVM
- 卡利本
- 肚带
- 棱镜
- 反应式界面
In your experience, which is better?
根据您的经验,哪个更好?
采纳答案by Pete OHanlon
It really depends on what you are trying to achieve, and how much infrastructure you want in place already, plus the ease with which you can find samples that help you out. I'm going to declare an interest here, because I've been actively involved in at least one MVVM framework, and I've had input into others through the WPF Disciples group, so I'm a little bit biased. Saying that, here goes:
这实际上取决于您想要实现的目标,以及您想要的基础设施数量,以及您可以轻松找到帮助您的示例。我将在这里声明一个兴趣,因为我已经积极参与了至少一个 MVVM 框架,并且我已经通过 WPF 门徒组向其他人提供了意见,所以我有点偏见。话虽如此,这里是:
Microsofts MVVM Toolkit- this is still very much in the alpha stages. When it was originally released, it took a bit of a savaging from the Disciples because of what it didn't do. Saying that, MS is looking to beef this framework up so it's one to watch - it's just not ready yet.
微软的MVVM 工具包- 这仍然处于 alpha 阶段。当它最初发布时,由于它没有做什么,它从门徒那里得到了一些野蛮。话虽如此,MS 正在寻求加强这个框架,因此值得一看——它只是还没有准备好。
MVVM Foundation- ah Josh Smith's version of the framework. Josh is one of the daddies of MVVM, and has been a huge advocate and teacher of the pattern. As a result, a lot of what you'll find in other frameworks has Josh's fingerprints all over it. This framework is intended to provide the basics of MVVM, and not to address some of the more esoteric issues. Originally this was intended only for WPF, but people such as Laurent Bugnion and myself have added functionality/projects that mean this will be a Silverlight compatible framework as well.
MVVM Foundation- 啊 Josh Smith 的框架版本。Josh 是 MVVM 的父亲之一,并且一直是该模式的大力倡导者和老师。因此,您在其他框架中会发现的很多内容都带有 Josh 的指纹。该框架旨在提供 MVVM 的基础知识,而不是解决一些更深奥的问题。最初这仅适用于 WPF,但 Laurent Bugnion 和我自己等人添加了功能/项目,这意味着这也将是一个与 Silverlight 兼容的框架。
WAF- no experience of it, so I can't comment on it I'm afraid.
WAF- 没有它的经验,所以我不能评论它恐怕。
MVVM Light- Laurent Bugnion's take on it, and just updated to version 2. This is a very good framework, but again it's not intended to cover every single aspect of MVVM applications. Given Laurent's background, it has very strong Silverlight and Blendability support in it.
MVVM Light- Laurent Bugnion 对它的看法,刚刚更新到第 2 版。这是一个非常好的框架,但它并不打算涵盖 MVVM 应用程序的每一个方面。鉴于 Laurent 的背景,它具有非常强大的 Silverlight 和 Blendability 支持。
UpdateLaurent has just informed me that the .NET 3.5 and .NET 4.0 versions are feature compatible. Wau to go Laurent.
更新Laurent 刚刚通知我 .NET 3.5 和 .NET 4.0 版本功能兼容。Wau 去 Laurent。
Cinch - Sacha Barber's excellent WPF only MVVM framework. This covers more ground than the frameworks I've talked about above. It's an excellent framework, and takes advantage of concepts covered in Bill Kempf's excellent Onyxproject. Onyx is intended to complement MVVM frameworks, and adds in functionality that's typically been hard for people to do in MVVM/WPF. Again, originally intended to be WPF only, Onyx has progressed to include SL compatibility - work I am particularly proud to have been involved in.
Cinch - Sacha Barber 优秀的 WPF 唯一 MVVM 框架。这比我上面谈到的框架涵盖了更多的基础。这是一个出色的框架,并利用了 Bill Kempf 出色的Onyx项目中涵盖的概念。Onyx 旨在补充 MVVM 框架,并添加人们在 MVVM/WPF 中通常难以做到的功能。同样,最初打算仅作为 WPF,Onyx 已经发展到包括 SL 兼容性 - 我特别自豪地参与了这项工作。
Prism- Again, I've never used it, but I've heard a lot of good things about it.
Prism- 同样,我从未使用过它,但我听说过很多关于它的好消息。
Ocean- Karl Shifflett, Program Manager on the Cider team, recently released a fully featured WPF MVVM framework. Again, this is an excellent framework and has lots to recommend it.
Ocean- Cider 团队的项目经理 Karl Shifflett 最近发布了一个功能齐全的 WPF MVVM 框架。同样,这是一个出色的框架,有很多值得推荐的地方。
The bottom line is, download the different frameworks take a look at them and work out which one fits most intuitively with the way you think and with your requirements. If you think that you might want to support Silverlight from the same codebase then the WPF only frameworks should be discounted.
最重要的是,下载不同的框架,看看它们,找出最符合你的思维方式和需求的框架。如果您认为您可能希望从相同的代码库支持 Silverlight,那么仅 WPF 的框架应该打折扣。
回答by Nasser Hadjloo
I found this article very useful http://www.japf.fr/2009/10/a-quick-tour-of-existing-mvvm-frameworks/So that I bring it here for upcoming users
我发现这篇文章非常有用http://www.japf.fr/2009/10/a-quick-tour-of-existing-mvvm-frameworks/所以我把它带到这里给即将到来的用户
I update the Cinch section and add silverlight support to its features
我更新了 Cinch 部分并为其功能添加了 Silverlight 支持
I'm sorry for the long story
我很抱歉讲了这么长的故事
Common features:
共同特征:
? ViewModelBase class (for the implementation of the INotifyPropertyChanged interface)
? RelayCommand like class to link UI command to ViewModel's handlers
? Unit tests comes with the framework
? ViewModelBase 类(用于实现 INotifyPropertyChanged 接口)
? RelayCommand 类将 UI 命令链接到 ViewModel 的处理程序
? 单元测试随框架一起提供
Cinch
肚带
? Author: Sacha Barber
? Silverlight support: no (Cinch version 2 supports Silverlight)
? Documentation: excellent, 6 articles published on CodeProject
? Hosting : CodePlex
? License: Code Project Open License
? Features:
attached behaviors
validation using IDataErrorInfo
support for IEditableObject
weak events creation and subscription
mediator messaging using weak events
IOC/DI support (using Unity)
services: event logger, message box, open save dialog, popup
threading helpers
support for menu items
closeable viewmodels
MVVM code generator
? 添加一名作者
? Silverlight 支持:否(Cinch 版本 2 支持 Silverlight)
? 文档:优秀,在 CodeProject 上发表了 6 篇文章
? 托管:CodePlex
? 许可证:代码项目开放许可证
? 特征:
依附行为
使用 IDataErrorInfo 进行验证
支持 IEditableObject
弱事件创建和订阅
使用弱事件的中介消息传递
IOC/DI 支持(使用 Unity)
服务:事件记录器、消息框、打开保存对话框、弹出窗口
线程助手
支持菜单项
可关闭的视图模型
MVVM 代码生成器
MVVM Light Toolkit
MVVM 灯光工具包
? Author: Laurent Bugnion
? Silverlight support: yes
? Documentation: many articles available on Laurent's blog + other developers as well
? Hosting: CodePlex
? License: MIT license
? Features:
MSI installer
VS project and item template
VS code snippets
Messenger system for inter-viewmodel communication
Handling events as commands
? 添加一名作者
? Silverlight 支持:是
? 文档:Laurent 的博客和其他开发人员提供的许多文章
? 托管:CodePlex
? 许可证:麻省理工学院许可证
? 特征:
微星安装程序
VS 项目和项目模板
VS 代码片段
用于视图模型间通信的 Messenger 系统
将事件作为命令处理
MVVM Helpers
MVVM 助手
? Author: Mark Smith
? Silverlight support: no
? Documentation: some articles on Mark's blog
? Hosting: personal website
? License: not defined
? Features:
attached behaviors
viewmodel creation using markup extension
attributes based validation
IOC/DI using ServiceProvider approach
closeable viewmodel
wait cursor (using new WaitCursor() { // your code here })
? 作者:马克·史密斯
? Silverlight 支持:否
? 文档:Mark 博客上的一些文章
? 托管:个人网站
? 许可证:未定义
? 特征:
依附行为
使用标记扩展创建视图模型
基于属性的验证
使用 ServiceProvider 方法的 IOC/DI
可关闭的视图模型
等待光标(使用 new WaitCursor() { // 你的代码在这里})
MVVM Foundation
MVVM 基金会
? Author: Josh Smith
? Silverlight support: no
? Documentation: articles about the Messenger implementation on Josh or Marlon Grech's blog
? Hosting: CodePlex
? License: MS-PL
? Features:
Messenger system for inter-viewmodel communication
PropertyChanged event monitor
? 作者:乔什·史密斯
? Silverlight 支持:否
? 文档:Josh 或 Marlon Grech 博客上有关 Messenger 实现的文章
? 托管:CodePlex
? 许可证:MS-PL
? 特征:
用于视图模型间通信的 Messenger 系统
PropertyChanged 事件监视器
Caliburn
卡利本
? Author: Rob Eisenberg
? Silverlight support: yes
? Documentation: complete online documentation available
? Hosting: CodePlex http://www.codeplex.com/caliburn
? License: MIT license
? Features:
commands are built on top of Actions and thus share many of the same features, including multiple input parameters, filters and automatic asynchronous execution
presenters that handles UI lifecycle issue such as handling activation, deactivation and shutdown semantics for various UI components
Caliburn applications are fully testable
various utilities such as a background task manager
supports various UI pattern (not MVVM only)
dependency injection container
? 作者:罗伯·艾森伯格
? Silverlight 支持:是
? 文档:提供完整的在线文档
? 托管:CodePlex http://www.codeplex.com/caliburn
? 许可证:麻省理工学院许可证
? 特征:
命令建立在动作之上,因此共享许多相同的功能,包括多个输入参数、过滤器和自动异步执行
处理 UI 生命周期问题的 Presenter,例如处理各种 UI 组件的激活、停用和关闭语义
Caliburn 应用程序完全可测试
各种实用程序,例如后台任务管理器
支持各种 UI 模式(不仅仅是 MVVM)
依赖注入容器
Onyx
玛瑙
? Author: William e Kempf
? Silverlight support: no
? Documentation: basic introduction available on CodePlex
? Hosting: CodePlex
? License: not specified
? Features:
ServiceLocator pattern
ViewModel creation using a custom markup extension
UI related services such as IDisplayMessage
? 添加一名作者
? Silverlight 支持:否
? 文档:CodePlex 上提供的基本介绍
? 托管:CodePlex
? 许可证:未指定
? 特征:
服务定位器模式
使用自定义标记扩展创建 ViewModel
UI 相关服务,例如 IDisplayMessage
Calcium
钙
? Author: Daniel Vaughan
? Silverlight support: no
? Documentation: 2 very detailed articles on CodeProject (part1 and part2)
? Hosting: CodePlex
? License: use, copy, modify, and/or distribute and keep the copyright!
? Features:
Module Manager for enabling or disabling of modules at runtime
messaging services for interacting with the user from the client or server using the same API
Command Service to associate WPF ICommands with content interfaces that only become active when an active view or viewmodel implements the interface
Region Adapters for ToolBars and Menus
Client-server logging ready to work out-of-the-box
Includes modules, such as a Web Browser, Text Editor, Output Window, and many more
Tabbed interface with dirty file indication (reusable across modules)
? 作者:丹尼尔·沃恩
? Silverlight 支持:否
? 文档:关于 CodeProject 的 2 篇非常详细的文章(第 1 部分和第 2 部分)
? 托管:CodePlex
? 许可:使用、复制、修改和/或分发并保留版权!
? 特征:
用于在运行时启用或禁用模块的模块管理器
使用相同的 API 从客户端或服务器与用户交互的消息服务
命令服务将 WPF ICommand 与仅在活动视图或视图模型实现接口时才变为活动的内容接口相关联
工具栏和菜单的区域适配器
客户端 - 服务器日志记录准备好开箱即用
包括模块,例如 Web 浏览器、文本编辑器、输出窗口等
带有脏文件指示的选项卡式界面(可跨模块重用)
nRoute
路由
? Author: Rishi
? Silverlight support: yes
? Documentation: many articles available on author's blog (see CodePlex project home page for the links)
? Hosting: CodePlex
? License: MS-PL
? Features:
support Blend3 behaviors and triggers models
resource locator framework
view services: OpenFileDialog, ShowMessage…
uses attributes to map View and ViewModel together
? 添加一名作者
? Silverlight 支持:是
? 文档:作者博客上提供了许多文章(有关链接,请参阅 CodePlex 项目主页)
? 托管:CodePlex
? 许可证:MS-PL
? 特征:
支持 Blend3 行为和触发器模型
资源定位器框架
查看服务:OpenFileDialog、ShowMessage…
使用属性将 View 和 ViewModel 映射到一起
Nito MVVM
尼托MVVM
? Author: Shammah
? Silverlight support: no
? Documentation: no
? Hosting: CodePlex
? License: not specified
? Features:
- various MVVM friendly implementations of the ICommand interface
? 添加一名作者
? Silverlight 支持:否
? 文件:没有
? 托管:CodePlex
? 许可证:未指定
? 特征:
- ICommand 接口的各种 MVVM 友好实现
Ocean
海洋
? Author: Karl Shifflet
? Silverlight support: no
? Documentation: articles available on Karl's blog
? Hosting: personal website
? License: not specified
? Features:
written in VB.Net
attribute based validation
viewmodel base classes: relaycommand, closeableviewmodel…
SQL server data access layer
? 添加一名作者
? Silverlight 支持:否
? 文档:Karl 博客上的文章
? 托管:个人网站
? 许可证:未指定
? 特征:
用VB.Net编写
基于属性的验证
viewmodel 基类:relaycommand、closeableviewmodel…
SQL 服务器数据访问层
Basic MVVM framework
基本的 MVVM 框架
? Author: Lester Lobo
? Silverlight support: no
? Documentation: sample application available with the library
? Hosting: CodePlex
? License: MS-PL
? Features:
delegating Commands\Keybinding
messaging between VM's
handling events as commands with attached behaviors
handling dialogs (and more) as services
VS code snippets
? 添加一名作者
? Silverlight 支持:否
? 文档:库中提供的示例应用程序
? 托管:CodePlex
? 许可证:MS-PL
? 特征:
委派命令\键绑定
VM之间的消息传递
将事件作为带有附加行为的命令处理
将对话(以及更多)作为服务处理
VS 代码片段
GoodLight
好光
? Author: Peter O'Hanlon ?Silverlight support: yes
? Documentation: sample application available with the library
? Hosting: CodePlex
? License: MS-PL
? Features:
“workspace” management (set of document that can be closed)
skin support
messaging between VM's
? 作者:Peter O'Hanlon ? Silverlight 支持:是的
? 文档:库中提供的示例应用程序
? 托管:CodePlex
? 许可证:MS-PL
? 特征:
“工作区”管理(可以关闭的文档集)
皮肤支持
VM之间的消息传递
回答by jbe
I try to describe the Frameworks missing in Pete's great answer:
我尝试描述 Pete 的精彩回答中缺少的框架:
MVVM Toolkit (Microsoft)is a very lightweight library with Visual Studio project templates that should support beginners with this pattern. If Microsoft gets good feedback for their Toolkit then they might implement this as a new Visual Studio (maybe 2010) project template.
MVVM Toolkit (Microsoft)是一个非常轻量级的库,带有 Visual Studio 项目模板,应该支持初学者使用这种模式。如果 Microsoft 对其 Toolkit 获得良好反馈,那么他们可能会将其作为新的 Visual Studio(可能是 2010)项目模板来实现。
Prism (Microsoft p&p)is a framework that provides more than the support for the MVVM pattern. The main goal of this project is to help you to build modularWPF and/or Silverlight applications. When you just need to implement the MVVM pattern or you are a beginner in .NET/WPF I won't recommend this project. See also: Link.
Prism (Microsoft p&p)是一个框架,它提供的不仅仅是对 MVVM 模式的支持。该项目的主要目标是帮助您构建模块化WPF 和/或 Silverlight 应用程序。当你只需要实现 MVVM 模式或者你是 .NET/WPF 的初学者时,我不会推荐这个项目。另见:链接。
WPF Application Framework (WAF)is a lightweight framework that helps you to create WPF apps with MVVM. It's just for WPF and so it doesn't support Silverlight. It goes a bit another way than most other MVVM frameworks with the introduction of Controllers. They are responsible for the application workflow and they mediate between various ViewModels.
WPF 应用程序框架 (WAF)是一个轻量级框架,可帮助您使用 MVVM 创建 WPF 应用程序。它仅适用于 WPF,因此不支持 Silverlight。与大多数其他 MVVM 框架相比,它采用了另一种方式,引入了Controllers。它们负责应用程序工作流,并在各种 ViewModel 之间进行调解。
回答by Pierreten
Meh. Mvvm doesn't really require an entire framework to support IMO. If you understand the concept, it's pretty straightforward to start off with a clean VM baseclass that implements INotify, and just go from there.
嗯。Mvvm 并不真正需要一个完整的框架来支持 IMO。如果您理解了这个概念,那么从一个实现 INotify 的干净 VM 基类开始,然后从那里开始就非常简单了。
回答by Andrei R?nea
Mix your own!
自己混!
I used EventAggregator from PRISM, with ViewModelBase from MVVM foundation and so on. I also tweaked the RelayCommand (DelegateCommand called in some places) to accept other data too, and so on.
我使用了 PRISM 的 EventAggregator,以及来自 MVVM 基金会的 ViewModelBase 等等。我还调整了 RelayCommand(在某些地方称为 DelegateCommand)以接受其他数据,依此类推。
I wouldn't recommend just one framework per se.
我不会只推荐一个框架本身。
回答by MCSean
my bet will be on Caliburn and MVVMlight, it seems that not many of these mvvm frameworks support silverlight. I can foresee that there will be more MVVM frameworks to choose from than the IoC frameworks, because it is harder to set up the feature boundary to the mvvm framework. I guess the best way to find out which one is better suit your project will be by listing/comparing their features.
我的赌注是 Caliburn 和 MVVMlight,似乎这些 mvvm 框架中没有多少支持 Silverlight。可以预见,MVVM 框架会比 IoC 框架更多,因为它更难给 mvvm 框架设置特征边界。我想找出哪个更适合您的项目的最佳方法是列出/比较它们的功能。
Also check out Mix10. I learn a lot from the talk : building your mvvm framework.
另请查看 Mix10。我从谈话中学到了很多东西:构建你的 mvvm 框架。
回答by dave
I'm using Prism and like it. One of the big things for me was that there would be other people out there who could help me if needed and good examples. Once you get the basics running, there are a whole bunch of extensions you'll need for your app and it is just so much easier when you're working with the same framework as others.
我正在使用 Prism 并且喜欢它。对我来说最重要的事情之一是,如果需要,还有其他人可以帮助我,并提供好榜样。一旦你掌握了基础知识,你的应用程序就需要一大堆扩展,当你使用与其他框架相同的框架时,它会变得更加容易。
回答by John Rayner
Another one to consider is MEFedMVVM. I've used it on a couple of projects and it's lightweight, non-intrusive and supports Silverlight and WPF. It's also able to support design-time data in Blend, for those who use that product.
另一个要考虑的是MEFedMVVM。我已经在几个项目中使用过它,它是轻量级的、非侵入式的并且支持 Silverlight 和 WPF。对于使用该产品的用户,它还能够支持 Blend 中的设计时数据。