Windows Phone 7 Tips (2)

简介:   上一篇Tips:Windows Phone 7 Tips (1), 今天也是分享10个Windows Phone 7 技巧,并提供离线文档下载。  1. 在Windows Phone 7中最简单的操作IsolatedStorge的代码: SaveNote()将文本框内容保存到Note.txt中,Edit()读取Note.txt到文本框中。

  上一篇Tips:Windows Phone 7 Tips (1), 今天也是分享10个Windows Phone 7 技巧,并提供离线文档下载。
  1. 在Windows Phone 7中最简单的操作IsolatedStorge的代码: SaveNote()将文本框内容保存到Note.txt中,Edit()读取Note.txt到文本框中。

  2. Windows Phone 7中的Orientation。

  分为 Portrait(竖屏)和Landscape(直屏)和PortraitOrLandscape(竖屏或横屏,在切换横竖屏时会自动切换)。并且又分为支持方向和启动方向,支持方向支持Portrait、Landscape和PortraitOrLandscape,启动方向支持Landscape、LandscapeLeft、LandscapeRight、Portrait、PortraitDown和PortraitUp。

  3. Windows Phone 7中常见的UI布局控件比较。

  Canvas:绝对定位控件,速度快,可用于游戏。

  Grid:网格定位控件,比较常用。

  StackPanel:自动定位控件,推荐使用与小区域。

  4. 简单叙述下Windows Phone 7中的生命周期。以下的一张图会对你有所帮助:

  具体的应用程序的事件及什么时候触发如下表: 

Application Event Occurs When Your Actions
Application_Launching The user taps the entry for an application on the installed applications screen, and a new instance of an application is created. Do not read application settings from the isolated storage as that will slow down the loading process; do not attempt to restore transient state. When an application launches, it should always appear as a new instance.
Application_Activated For this event to occur, two conditions must be met: (1) the user navigates away from your application, either by using a launcher or a chooser, or by starting another application and (2) the user then comes back to your application by either completing the launcher or chooser or using the hardware Back button. This event is not raised when an application is first launched. The application should allow the user to continue interaction as if she had never left the application; transient state information should be restored, but the application should not attempt to read the contents of the isolated storage to avoid potential slowdown.
Application_Deactivated The user navigates away from your application either by invoking a launcher or a chooser, or by launching another application. This event is not raised when your application is closing. You should save all transient (i.e., related to the current application session) state into the State dictionary. You should save persistent state to an isolated storage. Applications are given ten seconds to complete this event; after ten seconds, if this event is still not completed, an application will be terminated and not tombstoned.
Application_Closing The user uses the Back key to navigate past the first page of your application.

Save all of the persistent state into the isolated storage. 

  5. 确保你的Windows Phone 7 应用程序的第一个页面在5秒内加载渲染好,在20秒内你的应用程序可用!

  6. Windows Phone 7 中图片为Resource和Content的区别: 生成方式为Resource的图片会被编译到应用程序集(DLL)里,而生成方式为Content的图片则会被部署到XAP包中。

  当你把你的图片copy到项目中,图片的生成动作默认是资源(Resource),但我通常选择Content以获取更快的速度。我们应该如何选择图片的生成方式(Build Action)呢? 每种生成方式都有其用武之地:设置生成方式为Content意味着应用程序可以更快的加载图片资源;将生成方式设为Resource对你重新部署程序非常有用,这对类库项目十分合适的。

  7. Windows Phone 7中的物理回退键:在Tips (1)中曾讲到如何在PhoneApplicationPage_BackKeyPress事件中禁用物理回退键,即e.Cancel = true; 如果我们不编写代码,则当我们点击回退键时,Windows Phone 7会做哪些事情呢?据我所知,有如下三种情况:

  (1). 当你点击回退按钮式,程序必须返回上一个页面。

  (2). 如果你是在程序的第一个页面点击回退按钮,则应用程序必须推出。

  (3). 如果你的应用程序真在现实一个对话框或者Context Menu,点击回退按钮时,Windows Phone 7自动关闭对话框或者 Context Menu。

  8. 在Windows Phone 7 应用程序会有两种不同数据:持久性数据(Persistent Data)和瞬态状态(Transient State)。

  持久性数据:如配置文件(settings)、隔离存储空间(IsolatedStorage)。

  瞬态状态:存在于某个特定的程序回话中,如页面状态,web 请求缓存,瞬态状态以PhoneApplicationService.State 属性存在。

  有效性范围 存储位置 读/写
持久性数据 Phone上的所有应用程序 IsolatedStorage 程序打开/关闭,或者程序运行时
瞬态状态 应用程序回话 PhoneApplicationService的State属性 程序无效/激活时

  9. 我们最好不要在应用程序的Application_Launching和Application_Activated 事件中从隔离存储空间中加载数据,因为这样会使我们的程序启动变慢。

  10. IsolatedStorageSetttings 类提供一个简单序列化数据,我们可以使用现有的序列化方法(如json等)将数据持久到隔离存储空间中。

  CHM文件下载:(41KB)

目录
相关文章
|
Android开发 iOS开发 Windows
Windows Phone 寿终正寝了,这些经典机型你还记得吗?
不久前,随着最后一家WP手机厂商惠普宣布取消今后Windows Phone的研发计划,以及微软官方声明对WP8.1系统今后所有升级维护的终止,WP手机,作为曾经和安卓手机、苹果手机并驾齐驱的三大智能手机之一,正式寿终正寝。
1256 0
Windows Phone 寿终正寝了,这些经典机型你还记得吗?
|
XML 开发框架 前端开发
Windows Phone快速入门需掌握哪些能力
在此之前,先普及下Windows Phone的概念和开发工具的介绍。 Windows Phone是微软公司开发的手机操作系统,它将微软旗下的Xbox Live游戏、Xbox Music音乐与独特的视频体验集成至手机中。2012年6月21日,微软正式发布Windows Phone 8,采用和Windows 8相同的Windows NT内核,同时也针对市场的Windows Phone 7.5发布Windows Phone 7.8。
135 0
Windows Phone快速入门需掌握哪些能力
|
编解码 前端开发 JavaScript
Windows Phone 下开发 LBS 应用
基于位置的服务(Location Based Service,LBS),它是通过电信移动运营商的无线电通讯网络(如GSM网、CDMA网)或外部定位方式(如GPS)获取移动终端用户的位置信息(地理坐标,或大地坐标),在GIS(Geographic Information System,地理信息系统)平台的支持下,为用户提供相应服务的一种增值业务。
162 0
|
移动开发 Android开发 开发者
Windows Phone 8.1 新功能汇总 开发者预览版开放下载
在Build 2014大会上,微软正式发布了传闻已久的Windows Phone 8.1系统,所有的Windows Phone 8手机都可以升级,微软这次可谓是十分厚道。虽然并非迭代升级,但WP 8.1还是拥有很多重大更新,对于微软进一步完善移动平台拥有积极的意义。下面,就一起来了解一下WP 8.1的主要新特性。
230 0
Windows Phone 8.1 新功能汇总 开发者预览版开放下载