Reputation: 11331
I am working on a simple Windows Phone app, which has basically those functionality:
So here is the question:
I want to keep page 2 data alive in this case so I dont have to re-initialize page 2 everytime I go back from page 3. It would be perfect I can keep an instance of page 2 somewhere, and use that everytime I want to come back from page 3. So far I know there are two approach, one is in Page2 xaml I can have something like:
<Page
x:class "Page2.keepPageAlive"
...
The other one is using AddBackEntry. But I am not sure which one is fit in my case, or is there any other good approach.
Please share your idea, thank you.
Upvotes: 1
Views: 343
Reputation: 39007
As long as you navigate to page3 from page2, and go back to page2 using NavigationService.GoBack(), the page2 instance will be kept alive. So you basically have nothing to change.
Upvotes: 2
Reputation: 2525
In the WP7 Navigation stack, Page 2 will still exist. So if you navigated from Page 1 to Page 2 to Page 3, all 3 pages exist.
If you call NavigationService.GoBack() from Page 3, it will pop Page 3 off and restore the previous instance of Page 2, not create a new instance of Page 2. This is also what happens when you hit the Back button.
Only if you call NavigationService.Navigate() would a new instance be created.
Upvotes: 1