WP7 - how tell when navigating back to a page

Oct 28, 2010 at 5:25 AM


I have 3 pages, Page1, Page2 and Page3.

Page2 loads data. I only want to do this if I navigate from Page1 to Page2 and not if I am navigating back from Page3 to Page2.

How do I tell?



Nov 1, 2010 at 3:30 AM

Does anyone have any ideas on this?

I don't want to reload my data when I navigate back to a page using the back button.

Is there anyway to tell when this is happening rather than a page being navigated to directly?



Nov 1, 2010 at 11:21 AM
Edited Nov 1, 2010 at 11:22 AM

Sorry for the late reply. Unfortunately I have no ready recommendation for this scenario; with a quick search I couldn't find any simple way to access the information you need (but I'm not a Navigation Framework expert, so I may have missed something obvious).

I believe, however, that you might infere the information you need subscribing to NavigationService.Navigating event from a singleton service aimed to keep an "history" of page navigation sequence. Note that NavigatingCancelEventArgs also brings a NavigationMode property specifying the kind of navigation (Back, Forward, New, Refresh).
Once you have this history stored somewhere, should be easy to check the page you are navigating from.

I assume you already have a mechanism to restore the state (instead of loading data from scratch) for the page you navigate back to. 

Nov 1, 2010 at 8:00 PM

Thanks Marco. Sounds like a good fall back position. I'm hoping there is an easier way to do this.



Dec 9, 2010 at 3:19 AM

If you are navigating from 3 to 2 using the back button you can just add a boolean to your page like _isLoaded. Set _isLoaded = true once the data is loaded. The page will stay on the back stack and when you navigate back it  _isLoaded will still be true.

Dec 9, 2010 at 2:04 PM

Hook into navigating event and look at uri (can't remember property). it'll either be your current page (i.e. you just arrived here which is what you're after) or the page you're navigating to.