简体   繁体   中英

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.

How I initially did this, was to call NavigationService.Navigate in the MainPage.xaml Loaded event. 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).

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).

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 . In your circumstance, I think the custom UriMapper is probably the best solution.

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. Plus you simplify the app and pass validation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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