Tomb Strategy in Windows Phone 7, How to Preserve the State of Multiple Pages

I want to know what your persistence strategies are in a Windows 7 (wp7) application. when I say state, I mean the display state of the model of each page on the stack.

I recently asked a question about add- in issues in WP7, I can’t say if I need to restore or create instances / request new data , and the solution works. however, this approach seems to be ad-hoc and / or page specific. the code does not save the state of the pages preceding it.

I understand that when an application is activated or deactivated, you must handle restoring or backing up the state of the application, respectively. generated code for App.xaml.cs generates methods

private void Application_Activated(object sender, ActivatedEventArgs e) private void Application_Deactivated(object sender, DeactivatedEventArgs e) 

How can we use these methods to maintain the full state of the application during tombstones? I haven't found a good tutorial yet.

any help is appreciated.

+1
source share
1 answer

In practice, you can also forget these methods. You should not think of the tomb as a persisting state, but of persisting data.

You obviously cannot magically pile up the state of your entire application. And generally speaking, the state of the user interface of the page will be known only about a separate page.

What you need to do is find out which UI states you want to save, if any, and then save them along with the data (obviously) in PhoneApplicationService.State or IsolatedStorage.ApplicationSettings (depending on the size of the data).

For ViewModels, it’s pretty easy to tomb them. Just add the code to check if the gravestone exists, and then load the data using the view model at creation. And if you bind all the user interface settings to your viewing model, you will be pretty gold.

The code from your previous question can be used in your ViewModels constructor with almost the same result. And to keep the ViewModel persistent, just attach a local handler for the PropertyChanged and save the ViewModel state every time you call.

0
source

Source: https://habr.com/ru/post/1384344/


All Articles