解读Windows Phone开发的六个关键模块.pdf

解读Windows Phone开发的六个关键模块 今天给大家提供的是一系列的Windows Phone 7 开发的文章,包括提供试用版应用程序、返回 键、全景视图、项目模板以及页面间的导航等。本节内容是Windows Phone 7开发之:提供试用版应 用程序。 之前曾经写过如何将游戏添加到电话的游戏中心中。今天,我会向你展示为应用程序添加试用内 容是多么简单。例如,假设你创建了一个50关的游戏。可能你想让用户能免费体验前5关,但要想 玩后面的,他们就需要购买这个游戏。本文就像你展示如何做到。 使用LicenseInformation类 通过向我们的页面中添加Microsoft.Phone.Marketplace程序集和相应的名称空间,就可以访问 LicenseInformation类了,它直接与程序的 “付费”状态相关。 usingMicrosoft.Phone.Marketplace; 下一步是真正地使 LicenseInformation类,来创建一个实例: LicenseInformationli = new LicenseInformation(); 最后,LicenseInformation有一个非常棒的返回布尔值的方法叫IsTrial(),毫无悬念,它允许 我们检测程序是否处于试用状态。你可以很方便地将它用于一个if语句,就像这样: if(!li.IsTrial()) { //Do something that only paid users can do. } else { //Do something that all users, trial or paid, can do. } 测试试用模式 不幸的是,没有一种用来在试用和已付款状态间切换的内建机制。不过这处理起来很简单。我使 用了在App.xaml.cs文件中相同的if语句。用它来检测你是否在调试,如果是,创建一个被我叫做 “trialMode”的IsolatedStorageSetting。 下面是整个App()方法,包括App.xaml.cs文件自动生成的代码。在下面的例子中,我将trialMode 设为了TRUE。当你测试“已付费”模式时要将它关闭。 IsolatedStorageSettingssettings = IsolatedStorageSettings.ApplicationSettings; publicApp() { // Global handler for uncaught exceptions. UnhandledException += Application_UnhandledException; settings[ trialMode] = false; // Show graphics profiling information while debugging. if(System.Diagnostics.Debugger.IsAttached) { settings[ trialMode] = true; // Display the current frame rate counters. Application.Current.Host.Settings.EnableFrameRateCounter = true; // Show the areas of the app that are being redrawn in each frame. //Application.Current.Host.Settings.EnableRedrawRegions = true; // Enable non-production analysis visualization mode, // which shows areas of a page that are being GPU accelerated with a colored overlay. //Application.Current.Host.Settings.EnableCacheVisuali

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档