Win8 Metro UI應用的開發是一件非常有趣的事情,特別是它使用了非常奇特的Metro UI設計。如果現有傳統UI設計的應用,能夠很方便的移植到Win8上,並且也能夠充分利用Metro UI的魔力,那麼將是非常有有意義的事情。本篇部落格就是講述,在一般情況下,如何將傳統UI應用移植成Metro UI應用。
移植工作看上去比較的難,但是按照規律辦事,很多事情僅僅是時間和耐心問題。網友不妨使用9步法來完成你的應用移植:
- 下載並安裝Windows 8 Consumer Preview,下載並安裝Microsoft Visual Studio 11 Express Beta。
- 使用Microsoft Visual Studio 11 Express Beta 建立Metro UI應用程式項目,語言可以選擇你自己喜歡的C/C++、C#或者Visual Basic等。
- 將你要重複使用的檔案夾、原始碼、資源檔等拷貝到你的新項目中,並且在Solution Explorer中選擇Show All Filters。
- 用滑鼠右鍵選擇你的檔案夾、檔案等,將其添加入新項目中。
- 使用整個項目的尋找替換方法,將System.Windows替換成為Windows.UI.Xaml。
Silverlight XAML namespaces |
Windows Runtime XAML namespaces |
System.Windows |
Windows.UI.Xaml |
System.Windows.Automation |
Windows.UI.Xaml.Automation |
System.Windows.Automation.Peers |
Windows.UI.Xaml.Automation.Peers |
System.Windows.Automation.Provider |
Windows.UI.Xaml.Automation.Provider |
System.Windows.Automation.Text |
Windows.UI.Xaml.Automation.Text |
System.Windows.Controls |
Windows.UI.Xaml.Controls |
System.Windows.Controls.Primitives |
Windows.UI.Xaml.Controls.Primitives |
System.Windows.Data |
Windows.UI.Xaml.Data |
System.Windows.Documents |
Windows.UI.Xaml.Documents |
System.Windows.Input |
Windows.UI.Xaml.Input |
System.Windows.Interop |
Windows.UI.Xaml.Interop |
System.Windows.Markup |
Windows.UI.Xaml.Markup |
System.Windows.Media |
Windows.UI.Xaml.Media |
System.Windows.Media.Animation |
Windows.UI.Xaml.Media.Animation |
System.Windows.Media.Imaging |
Windows.UI.Xaml.Media.Imaging |
System.Windows.Media.Media3D |
Windows.UI.Xaml.Media.Media3D |
System.Windows.Navigation |
Windows.UI.Xaml.Navigation |
System.Windows.Printing |
Windows.UI.Xaml.Printing |
System.Windows.Resources |
Windows.UI.Xaml.Resources |
System.Windows.Shapes |
Windows.UI.Xaml.Shapes |
- 拷貝能夠重複使用的XAML代碼到項目的XAML檔案中去(你可以根據需要建立新的XAML檔案)。
- 編譯你的項目,使用錯誤資訊快速定位需要修改的地方。使用Windows Runtime APIs替換元代的.NET APIs。
- 對不能夠簡替換的代碼部分,使用注釋將其暫時屏蔽,以便日後慢慢修改。重複7和8的方法直到整個項目完全編譯通過。
- 對暫時屏蔽的代碼部分逐一解決。完成所有相關的修改後,你的移植工作基本完成,下面的工作就是解bugs了。
怎麼樣?是不是比較簡單!還不現在動手試一試J。