Reputation: 760
I'm developing a WP 8 app and I've a problem with navigation.
I can't find a way to navigate to a page on my back stack without losing my actual page state.
The situation is this:
So this is it: A --> B --> A --> B, it's kind of a cycle but it isn't one. Page A shows items that are also shown in page B with less detail, but from page B I can go to page A to see the details and then back and back again.
It may seem complicated but I assure you its pretty intuitive :) it works like this on Android and iOS.
Is there anyway to add page B to the navigation stack before page A so when I call NavigationService.GoBack() it goes back to page A with it previous state and then do the same from A to B.
Thanks in advance!!!
Upvotes: 0
Views: 813
Reputation: 12019
There are a couple of options. If you use the standard MVVM pattern then you're not really saving "page state" (unless you mean things like scroll position in lists or selected text control) - you're saving data. And that data will be there the next time you navigate to Page B. You can watch this video and the MSDN article it points to for more information on databinding and how to store the data in global state that will be re-bound to the page the next time you navigate.
If databinding doesn't solve the problem, another option is to not use different pages at all, but to just have A and B as two different containers on the same physical page. You can then trap the back button to fake going "back" when you need to toggle back to Container A.
Upvotes: 1
Reputation: 4490
Use this help topic to learn how to preserve and restore page state for Windows Phone 8. Navigation stack can store only page URI and a small amount of data (in the URI parameter).
Like this:
NavigationService.Navigate(new Uri("/SecondPage.xaml?var=value", UriKind.Relative));
At the SecondPage.xaml
you can get the value of val. Here is detailed example.
if (NavigationContext.QueryString.TryGetValue("val", out msg))
Upvotes: 0