简体   繁体   English

以编程方式更改Windows Phone 7应用程序启动页面

[英]Programatically Changing Windows Phone 7 Application Startup Page

I've created a simple bus time table application, which contains a favourites page, a search page and a results page. 我创建了一个简单的公交车时间表应用程序,其中包含一个收藏夹页面,一个搜索页面和一个结果页面。 If the user has a favourite, then I'd like them to be shown the favourites page, otherwise they should be shown the search page. 如果用户有收藏夹,那么我希望他们显示在“收藏夹”页面上,否则,应该在搜索页面上显示他们。 Also if the user has performed a search in the last 10 mins, then they should go to the results page. 同样,如果用户在最近10分钟内执行了搜索,那么他们应该转到结果页面。

How I initially did this, was to call NavigationService.Navigate in the MainPage.xaml Loaded event. 我最初的操作方式是在MainPage.xaml Loaded事件中调用NavigationService.Navigate。 This seemed to work fine, but I failed Microsoft's validation due to the fact that the back button no longer exited the app (due to the hidden page still being in the navigation stack). 这似乎工作正常,但由于后退按钮不再退出应用程序(由于隐藏页面仍在导航堆栈中),我未能通过Microsoft的验证。

I then thought of having a Loaded property in my app, and if the user had already been redirected on login, then the App would either call Quit or GoBack, but neither option seems to be viable (there's no Quit, and calling GoBack on the first page will fail). 然后,我想到了在我的应用程序中具有Loaded属性,并且如果用户已经在登录时被重定向,则该应用程序将调用Quit或GoBack,但是这两个选项似乎都不可行(没有Quit,并且在第一页将失败)。

Does anyone know the best way to implement page redirections or clean up the navigation stack? 有谁知道实现页面重定向或清理导航堆栈的最佳方法?

There are a number of ways to implement this kind of approach as documented by Peter Torr in his blog post Redirecting an initial navigation . 彼得·托尔(Peter Torr)在他的博客文章“ 重定向初始导航”中介绍了多种实现这种方法的方法。 In your circumstance, I think the custom UriMapper is probably the best solution. 在您的情况下,我认为自定义UriMapper可能是最好的解决方案。

I would suggest always showing the main page to the user. 我建议始终向用户显示主页。 The main page should allow access to favorites, searches and results. 主页应允许访问收藏夹,搜索和结果。 The user will choose the page they want. 用户将选择他们想要的页面。 You may think you are doing the user favour by pre-loading what you think they want but for every 8 where you are correct there will be 2 that want another page. 您可能认为您正在通过预加载您想要的内容来赢得用户的青睐,但是每8个您正确的地方就会有2个想要另一个页面。 Plus you simplify the app and pass validation. 另外,您可以简化应用程序并通过验证。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM