简体   繁体   中英

Saving page state in a 3 page app in WP7

Well it's my first question here and as far as i searched i didn't find a solution for my problem. I am coding my first rssreader app for WP7 and i am facing a problem with the page state. I have 3 pages and navigation goes like that mainpage >>> listitemspage >>> detailspage. Mainpage is a databound model with preconfigured feeds category items (urls and names), listitempage is a page in which i implemented a webclient to read feed items and detailspage is where i pass the details of the selected feed item from listitempage. Page state working in these situations:

mainpage >>> start button >>> back button (OK)<br/>
listitempage >>> start button >>> back button (Doesn't work)<br/>
detailspage >>> start button >>> back button (OK)<br/>

In detailspage i save the page state using OnNavigatedTo/From and State.TryGetValue This seems to work but if i create a button with a browser task so the user can navigate to the full article when the browser open and user press back button the details page state works. If the user press for second time the back button then the app is exiting instead of navigating back to the listitempage. So i have this problem too:

detailspage >>> browserbuttontask >>> backbutton >>> restorepage >>> backbutton->exit<br/>

Any ideas?

I'd recommend using the Tombstone helper on codeplex written by Matt Lacey (of the Windows Phone User Group).

http://tombstonehelper.codeplex.com/

It will either solve all your problems very easily or at the very least show you how to write your page states off to isolated storage for long term use (remember the state cache only survives while the device is powered and so long as the phone doesn't need to clear it's memory)

Hope this helps Rgds Simon

If you want to save page state without messing with IsolatedStorage try SterlingDB. It uses IsolatedStorage but it is very simple to setup and use. You can add sterling via nuget. You will have to stick data you want persisted in a class but saving and loading is simple.

Beyond that you also might want to look at Caliburn Micro. It adds page lifecycle to your ViewModels like OnInitialize, OnActivate, OnDeactivate. It also adds some nice stuff for WP7 like automagically persisting properties on a ViewModel to IsolatedStorage or phone state.

http://www.sterlingdatabase.com/

It sounds like your application is throwing an exception when restoring state to your list page, which has the effect of terminating the application.

Have you tried doing all this with the debugger attached? It should show you what exception is being thrown and where.

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