Windows Phone 7 Tips (2)
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:自动定位控件,推荐使用与小区域
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。
持久性数据:如配置文件(settings)、隔离存储空间(IsolatedStorage)
瞬态状态:存在于某个特定的程序回话中,如页面状态,web 请求缓存,瞬态状态以PhoneApplicationService.State 属性存在 .
有效性范围 | 存储位置 | 读/写 | |
持久性数据 | Phone上的所有应用程序 | IsolatedStorage | 程序打开/关闭,或者程序运行时 |
瞬态状态 | 应用程序回话 | PhoneApplicationService的State属性 | 程序无效/激活时 |
9. 我们最好不要在应用程序的Application_Launching和Application_Activated 事件中从隔离存储空间中加载数据,因为这样会使我们的程序启动变慢。
10. IsolatedStorageSetttings 类提供一个简单序列化数据,我们可以使用现有的序列化方法(如json等)将数据持久到隔离存储空间中
如果您喜欢我的文章,您可以通过支付宝对我进行捐助,您的支持是我最大的动力https://me.alipay.com/alexis
作者:Alexis
出处:http://www.cnblogs.com/alexis/
关于作者:专注于Windows Phone 7、Silverlight、Web前端(jQuery)。
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,如有问题,可以通过shuifengxuATgmail.com 联系我,非常感谢。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架