欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

Windows Phone 7 Tips (2)

程序员文章站 2022-05-13 22:01:28
1. 在windows phone 7中最简单的操作isolatedstorge的代码: savenote()将文本框内容保存到note.txt中,edit()读取note.txt到文本框中 2...

1. 在windows phone 7中最简单的操作isolatedstorge的代码: savenote()将文本框内容保存到note.txt中,edit()读取note.txt到文本框中

Windows Phone 7 Tips (2)

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中的生命周期。以下的一张图会对你有所帮助

 Windows Phone 7 Tips (2)

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

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 请求缓存,瞬态状态以aspx" target="_blank">phoneapplicationservice.state 属性存在 .

 

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

 

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

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



作者:alexis