windows 8 apps dev.整理及分享

32
Windows 8 Apps Dev. 整理及分享 Liyao Chen.

Upload: liyao-chen

Post on 24-May-2015

607 views

Category:

Technology


5 download

TRANSCRIPT

Page 1: Windows 8 apps dev.整理及分享

Windows 8 Apps Dev. 整理及分享

Liyao Chen.

Page 2: Windows 8 apps dev.整理及分享

OS: Windows 8IDE: Visual Studio 2012

開發環境

Page 3: Windows 8 apps dev.整理及分享

主要語言

C# + XAML當然你也可以用JavaScript + HTML + CSSC++不過這裡不討論就是了

Page 4: Windows 8 apps dev.整理及分享

主要語言 C# + XAMLC#有什麼厲害的地方?

● LINQ● Lambda● 非同步程式 Async / Await

XAML是什麼? 我只知道XML● Data Binding● INotifyPropertyChanged● Bindable

Page 5: Windows 8 apps dev.整理及分享

C# - LINQ以簡單、直覺的方式查詢資料,並且讓你為資料進行分組。-深入淺出C#

Page 6: Windows 8 apps dev.整理及分享

C# - Lambda 物件搜尋?

參考資料:Huan-Lin學習筆記

Page 7: Windows 8 apps dev.整理及分享

C# - Lambda 物件資料子集?

Page 8: Windows 8 apps dev.整理及分享

C# - 非同步程式 Async / Await

避免效能瓶頸和增強應用程式整體回應。讓畫面不會卡住,提升使用者經驗。

資料來源:msdn - async

Page 9: Windows 8 apps dev.整理及分享

C# - 非同步程式 Async / Await

過去我們這麼寫..

假設這個request花1秒完成,你就App就卡住1秒

資料來源:msdn - async

Page 10: Windows 8 apps dev.整理及分享

C# - 非同步程式 Async / Await

現在我們可以這樣寫..

呼叫此方法時會產生另一個"執行序"來執行任務,簡單來說就

是叫別人去買晚餐當你繼續看電視。資料來源:msdn - async

Page 11: Windows 8 apps dev.整理及分享

XAMLXAMLXAML 的全名為 Extensible Application Markup Language,原為 WPF (Windows Presentation Framework) 的一部份,是一種基於 XML 衍生而出的宣告式使用者介面描述語言,外觀與 HTML 相似,平台會自動透過 .Net Framework 中的反射 (Reflection) 機制,將 XAML 中描述的物件,轉換為平台上使用的語言宣告、定義,以方便在之後供 Code-Behind 的程式碼使用或是進行互動。

Page 12: Windows 8 apps dev.整理及分享

XAML+Data Binding把物件屬性及內容綁給UI呈現

資料來源:msdn - data binding to controls

Page 13: Windows 8 apps dev.整理及分享

XAML+Data Binding

將物件設定到 textBox1

setter / getter 必須

Page 14: Windows 8 apps dev.整理及分享

XAML+Data Binding

Page 15: Windows 8 apps dev.整理及分享

Binding再進化 - INotifyProptertyChanged

物件資料更改時UI物件要能跟著更新

繼承INotifyPropertyChenged

Page 16: Windows 8 apps dev.整理及分享

有點複雜看不太懂...

Binding再進化 - 有沒有更簡單的方式?INotifyPropertyChanged = > Bindable

繼承INotifyPropertyChenged

實作SetProperty簡化Setter

Page 17: Windows 8 apps dev.整理及分享

沒關係,會用就好

Binding再進化 - 有沒有更簡單的方式?INotifyPropertyChanged = > Bindable

原本的setter用不到囉

這樣簡單多了

Page 18: Windows 8 apps dev.整理及分享

MVVMModel - View - ViewModel

Page 19: Windows 8 apps dev.整理及分享

Framework (MVVM)Model:用來描述資料實體(Entity)的簡單類別(Class),也可以在這邊實作商業邏輯以及與資

料庫溝通等資料存取相關的功能。

ViewModel:供View使用的Model,透過公開的屬性(public property)給View進行Binding,供其

使用。

View:

其實就是XAML檔,也就是使用者介面

,使用者介面設計人員只需要在Blend中進行

對它的編輯,並透過Binding來和ViewModel溝通(將DataContext指定為某個ViewModel,以更進一步的與其中的屬性進行Binding)。

資料來源:[MVVM]初步認識MVVM設計模式

Page 20: Windows 8 apps dev.整理及分享

MVC適合於大型系統,它可以分層且可以在實體層面切割為不同的機器或服務,只要彼此間具有適當的通訊協定即可。

MVVM適合像 XAML 這種與程式碼無關 (code ignorance) 的使用者介面設計,只要 View 中下特定的指令與 ViewModel 串接,就可以享有 ViewModel 溝通的功能,而 ViewModel 只需做一些特別的介面實作,即可平順的和 View 溝通。

資料來源:[Architecture] MVP, MVC, MVVM, 傻傻分不清楚~

MVC vs MVVM

Page 21: Windows 8 apps dev.整理及分享

減少View的Code

資料來源:msdn - Implementing the MVVM Pattern

MVVM XAML code lines

Windows 8 X 751

WP8 O 121

Page 22: Windows 8 apps dev.整理及分享

Windows 8and

Windows Phone 8你可能以為他們都一樣

事情不是像憨人想的那麼簡單

Page 23: Windows 8 apps dev.整理及分享

Overlap of XAML controls

資料來源:msdn - XAML controls comparison

Windows 8 Windows Phone 8

AppBar ApplicationBar

ComboBox ListPicker

GridView, ListView LongListSelector, LongListMultiSelector

ToggleSwitch Toggle

VarableSizeWrapGrid, WrapGrid

WrapPanel

WebView WebBrowser

Panorama

Pivot

Page 24: Windows 8 apps dev.整理及分享

API NamespaceWindows 8

Windows.UI.Xaml.Imaging

Windows Phone 8System.Windows.Media.Imaging

Page 25: Windows 8 apps dev.整理及分享

NavigationWindows 8

//直接傳物件

Frame.Navigate(typeof(DetialsPage), e.CleckedItem);

Windows Phone 8//傳參數

NavigationService.Navigate(new Uri("/DetailsPage.xaml?Id=10, UriKind.Relative));

Page 26: Windows 8 apps dev.整理及分享

還有很多

● Storing Files - Local● Storing Files - Roaming● ...請參考WP to W8: API Mapping

還有許多驚喜等你去發現。

Page 27: Windows 8 apps dev.整理及分享

Better way?生命自然會找到它的出口...

Page 28: Windows 8 apps dev.整理及分享

Portable Libraries

Page 29: Windows 8 apps dev.整理及分享

Portable Libraries

Page 30: Windows 8 apps dev.整理及分享

Portable Libraries

資料來源:How to Make Portable Class Libraries Work for You

Page 31: Windows 8 apps dev.整理及分享

Portable 帶來的好處

GoodMaintain同一份商業邏輯

Unit TestNo Good

Portable 所支援的API較少