收藏自:http://knightswarrior.blog.51cto.com/1792698/1669687跨域
2008年第一次在WPF中使用MVVM模式以後,就一直熱衷於耦合隔離、模塊化與重 構、UI和邏輯分離、單元測試以及後面的領域模型。談及MVVM模式,本身也開發過一套框架,但沒有長期更新和維護,因此索性就一直使用Prism和 MVVM Light。到2012年的時候,看到HTML5的大行其道和Silverlight的衰落,果斷把主要精力投入到ASP.NET MVC和Knockout的開發和研究當中,雖然Knockout比較容易上手且方便使用,但總以爲沒有在WPF和Silverlight中使用MVVM 那麼酣暢淋漓。瀏覽器
WPF/Silverlight架構 |
Webapp |
|
MVVM框架框架 |
· Prismide · MVVMLight模塊化 · Caliburn(Caliburn.Micro)工具 · MVVM Helpers性能 · Cinch單元測試 · MVVMFoundation |
· AngularJS · Knockout (or use Durandal) · Backbone.js · Ember.js · Epitome · Agility.js |
儘管後面嘗試過其餘框架,好比經過Durandal 實現SPA讓我以前對Knockout的種種不便有所改觀,但始終仍是有所缺憾,直至如今使用Angular,尤爲是Angular + TypeScript才發現一切問題都不復存在了。
(以前使用WPF/Silverlight的最大問題實際上是很難招到合適的人員作美工和設計,由於不多人會專門投入到Blend和XAML的研究當中,但如今使用Web就會發現資源是那麼的豐富,無論是人力資源仍是開源社區)
功能 |
WPF/Silverlight |
AngularJS |
UI |
XAML |
HTML+CSS |
設計工具 | Design/Blend and Visual Studio | All professional design tools |
控件模板和自定義控件 |
Control Templates or Custom Control |
Custom Directives (Element) |
動畫 |
System.Windows.Media.Animation |
CSS3 Animations and/or JavaScript via ngAnimate |
樣式和模板 |
XAML/Resources |
CSS3 and LESS |
樣式繼承和關聯 |
Implicit Styles and/or BasedOn |
LESS Mixins |
轉換和過濾 |
IValueConverter |
Filters |
綁定Model到UI |
ViewModel and DataContext |
Controller and Scope |
服務重用 |
Prism Service Locator |
Custom Services/Service Factory |
事件 |
Routed Events |
$emit and $broadcast |
模塊化 |
MEF and/or Prism Module Catalog |
Angular Modules |
Services |
WCF or WCF RIA Services |
RESTful services (accessed via the Angular $http/$resource Services) |
導航與路由 |
UriMapper |
Routing |
內部組件通訊 |
Prism Event Aggregator or Messager |
Shared Services |
視頻 |
MediaElement |
HTML5 Video Element |
脫離瀏覽器運行 |
Yes |
Yes, via Chrome Apps |
封裝UI邏輯 |
Behaviors |
Custom Directives (Attribute) |
UI與邏輯分離 |
Control or Data Templates |
CSS/LESS |
跨域請求 |
Access-Policy |
CORS |
單向數據綁定 |
BindingMode.One |
Ng-Bind |
雙向數據綁定 |
BindingMode.TwoWay |
Ng-Model |
單向數據源綁定 |
BindingMode.OneTime |
Ng-Model |
開源模板 |
Modern UI or MahApps |
Bootstrap or Foundation |
瀏覽器支持 |
Need silverlight plugin or XBAP |
All supported |
因此如今將架構由Knockout到Angular的調整並使用到新項目的開發,具體以下:
到目前爲止,尚未發現Angular有什麼大的技術難題或者性能問題,若是有Angular項目經驗的朋友,不妨留言討論,學習共勉!
另外,不少人發郵件問WPF是否會像Silverlight同樣消亡,其實這個問題很難回答,尤爲在目前這個不光是微軟主導的開發環境下 (HTML5流行度遠甚於XAML,IOS和Android的大行其道與Windows Phone的不溫不火,Windows的命運尚不知曉),可能連微軟本身也不能很好地解答這個問題,因此一切只能由市場和時間來慢慢決定。