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

将wp7应用移植到metro主要做这两方面的工作

  1. 换ui控件,因为silverlight的ui控件不可以直接用在metro上
  2. 换api,silverlight的api同样也不能直接用在windows runtime上

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

  • 分辨率,wp7统一为480*800,但是win8支持各种分辨率
  • 输入,wp7是触屏,而win8不仅触屏,还支持鼠标,键盘
  • 硬件特性,例如手机通信网络,GSM,3G
  • XNA, win8目前还不支持xna, 而是用directx来做3D

移植流程

  1. 使用vs11建立一个metro工程
  2. 将wp7工程的所有文件全都拷到新工程的目录下,选中“显示所有文件”并且包含在项目中
  3. 将所有的 命名空间 System.Windows 替换为 Windows.UI.Xaml
  4. 修改xaml文件,win8下只有grid可用,而PhoneApplicationPage则不可用了
  5. 编译,根据提示的错误,用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

    

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
代码介绍 MetroForWinForm(win8风格模版) using System; using System.Drawing; using System.Globalization; using System.Windows.Forms; using MetroFramework.Forms; namespace MetroFramework.Demo { public partial class MainForm : MetroForm { public MainForm() { InitializeComponent(); metroStyleManager.Theme = MetroThemeStyle.Default; metroStyleManager.Style = MetroColorStyle.Teal; } private void metroTileSwitch_Click(object sender, EventArgs e) { var m = new Random(); int next = m.Next(0, 13); metroStyleManager.Style = (MetroColorStyle)next; } private void metroTile1_Click(object sender, EventArgs e) { metroStyleManager.Theme = metroStyleManager.Theme == MetroThemeStyle.Light ? MetroThemeStyle.Dark : MetroThemeStyle.Light; } private void metroButton1_Click(object sender, EventArgs e) { MetroTaskWindow.ShowTaskWindow(this, "SubControl in TaskWindow", new TaskWindowControl(), 10); } private void metroButton2_Click(object sender, EventArgs e) { MetroMessageBox.Show(this, "Do you like this metro message box?", "Metro Title", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Asterisk); } private void metroButton5_Click(object sender, EventArgs e) { metroContextMenu1.Show(metroButton5, new Point(0, metroButton5.Height)); } private void metroButton6_Click(object sender, EventArgs e) { MetroMessageBox.Show(this, "This is a sample MetroMessagebox `OK` only button", "MetroMessagebox", MessageBoxButtons.OK, MessageBoxIcon.Information); } private void metroButton10_Click(object sender, EventArgs e) { MetroMessageBox.Show(this, "This is a sample MetroMessagebox `OK` and `Cancel` button", "MetroMessagebox", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); } private void metroButton7_Click(object sender, EventArgs e) { MetroMessageBox.Show(this, "This is a sample MetroMessagebox `Yes` and `No` button", "MetroMessagebox", MessageBoxButtons.YesNo, MessageBoxIcon.Question); } private void metroButton8_Click(object sender, EventArgs e) { MetroMessageBox.Show(this, "This is a sample MetroMessagebox `Yes`, `No` and `Cancel` button", "MetroMessagebox", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); } private void metroButton11_Click(object sender, EventArgs e) { MetroMessageBox.Show(this, "This is a sample MetroMessagebox `Retry` and `Cancel` button. With warning style.", "MetroMessagebox", MessageBoxButtons.RetryCancel, MessageBoxIcon.Warning); } private void metroButton9_Click(object sender, EventArgs e) { MetroMessageBox.Show(this, "This is a sample MetroMessagebox `Abort`, `Retry` and `Ignore` button. With Error style.", "MetroMessagebox", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error); } private void metroButton12_Click(object sender, EventArgs e) { MetroMessageBox.Show(this, "This is a sample `default` MetroMessagebox ", "MetroMessagebox"); } private void metroButton4_Click(object sender, EventArgs e) { var testform = new TestForm1(); testform.ShowDialog(); } private void metroButton4_Click_1(object sender, EventArgs e) { metroTextBox2.Focus(); } } }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值