您的位置:首页 > 编程语言 > C#

使用C#开发Metro 风格应用的路线图 -- 移植wp7应用到metro上

2012-12-26 11:21 1171 查看
将wp7应用移植到metro主要做这两方面的工作:

换ui控件,因为silverlight的ui控件不可以直接用在metro上

换api,silverlight的api同样也不能直接用在windows runtime上

在移植前,需要考虑以下因素

分辨率,wp7统一为480*800,但是win8支持各种分辨率

输入,wp7是触屏,而win8不仅触屏,还支持鼠标,键盘

硬件特性,例如手机通信网络,GSM,3G

XNA, win8目前还不支持xna, 而是用directx来做3D

移植流程

使用vs11建立一个metro工程

将wp7工程的所有文件全都拷到新工程的目录下,选中“显示所有文件”并且包含在项目中

将所有的 命名空间 System.Windows 替换为 Windows.UI.Xaml

修改xaml文件,win8下只有grid可用,而PhoneApplicationPage则不可用了

编译,根据提示的错误,用windows runtime api 替换 .net api for metro styles

改进可移植性

最好别用一些设计模式,比如MVVM这种分享UI和逻辑的框架,因为有些代码可能是某些平台特有的

将一些可重用的代码分离出来,在项目中以 添加已有项 的方式来加代码,并且在 添加 时选择 以链接方式添加。(在添加的右下角按钮可以选择)

如果在共享文件中有平台特有代码,需要使用条件编译(xaml不支持)

选择 可移植类库 来创建跨平台库

移植UI,这里有一个UI库对应表

Silverlight XAML namespacesWindows Runtime XAML namespaces
System.WindowsWindows.UI.Xaml
System.Windows.AutomationWindows.UI.Xaml.Automation
System.Windows.Automation.PeersWindows.UI.Xaml.Automation.Peers
System.Windows.Automation.ProviderWindows.UI.Xaml.Automation.Provider
System.Windows.Automation.TextWindows.UI.Xaml.Automation.Text
System.Windows.ControlsWindows.UI.Xaml.Controls
System.Windows.Controls.PrimitivesWindows.UI.Xaml.Controls.Primitives
System.Windows.DataWindows.UI.Xaml.Data
System.Windows.DocumentsWindows.UI.Xaml.Documents
System.Windows.InputWindows.UI.Xaml.Input
System.Windows.InteropWindows.UI.Xaml.Interop
System.Windows.MarkupWindows.UI.Xaml.Markup
System.Windows.MediaWindows.UI.Xaml.Media
System.Windows.Media.AnimationWindows.UI.Xaml.Media.Animation
System.Windows.Media.ImagingWindows.UI.Xaml.Media.Imaging
System.Windows.Media.Media3DWindows.UI.Xaml.Media.Media3D
System.Windows.NavigationWindows.UI.Xaml.Navigation
System.Windows.PrintingWindows.UI.Xaml.Printing
System.Windows.ResourcesWindows.UI.Xaml.Resources
System.Windows.ShapesWindows.UI.Xaml.Shapes
但是下面几个命名空间在windows runtime上没有对应的

System.Windows.Ink

System.Windows.Media.Effects

System.Windows.Messaging

XAML在Silveright与metro上使用的不同

布局: windows runtime上没有 Pivot 和 Panorama,取而代之的是FlipView

    windows runtime上没有 ApplicationBar,,取而代之的是AppBar

    一些在屏幕方向上的不同

磁片和通知:大部分都一样,但是有一些细节不同

数据:metro同样没有内建客户端数据库, 更新ui同样是实现INotifyPropertyChangedINotifyCollection

页面导航:同样是通过后退来导航,但是metro应用导航时不用提供具体的uri地址,只需要指明目标页面的在x:Class的属性里定义的类型即可,但是不支持清栈和uri mapping.



关于metro和silverlight的一些api的映射关系如下

API typeSilverlight API namespacesWindows Runtime API namespaces (C#/Visual Basic)
DevicesMicrosoft.Devices, Microsoft.Devices.Radio, Microsoft.Devices.SensorsWindows.Devices.Enumeration, Windows.Devices.Enumeration.Pnp, Windows.Devices.Input, Windows.Devices.Sensors
Windows Phone app model and environmentMicrosoft.Phone, Microsoft.Phone.Info, Microsoft.Phone.Notification, Microsoft.Phone.Reactive, Microsoft.Phone.Shell, Microsoft.Phone.TasksWindows.Networking.PushNotifications, Windows.Devices.Sms, Windows.ApplicationModel.Background, Windows.ApplicationModel.Contacts, Windows.ApplicationModel.Contacts.Provider, Windows.ApplicationModel.Core
MapsMicrosoft.Phone.Controls.Maps, Microsoft.Phone.Controls.Maps.AutomationPeers, Microsoft.Phone.Controls.Maps.Core Microsoft.Phone.Controls.Maps.Design Microsoft.Phone.Controls.Maps.Overlays, Microsoft.Phone.Controls.Maps.PlatformWindows.Devices.Geolocation
MarketplaceMicrosoft.Phone.MarketplaceWindows.ApplicationModel.Store
Networking and syndicationMicrosoft.Phone.Net, Microsoft.Phone.Net.NetworkInformationWindows.Networking, Windows.Networking.BackgroundTransfer, Windows.Networking.Connectivity, Windows.Networking.NetworkOperators, Windows.Networking.Sockets, Windows.Web.AtomPub, Windows.Web.Syndication
Programming and data modelsSystemWindows.Foundation, Windows.Foundation.Collections, Windows.Foundation.Metadata, Windows.Data.Xml.Dom, Windows.Data.Xml.Xsl, Windows.Data.Json
LocationSystem.Device.LocationWindows.Devices.Geolocation, Windows.Networking.Proximity
Automation and diagnosticsSystem.Diagnostics, System.Windows.Automation.PeersWindows.Foundation.Diagnostics
Graphics (3D transforms)XNA Framework Class Library,Content Pipeline Class LibraryNo equivalent at this time.
Controls and UI infrastructureMicrosoft.Phone.Controls, Microsoft.Phone.Controls.Primitives,Windows.UI.ApplicationSettings, Windows.UI.Core, Windows.UI.Input, Windows.UI.Notifications, Windows.UI.ViewManagement
StorageSystem.IO.IsolatedStorage classWindows.Storage, Windows.Storage.FileProperties
    
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: