1
votes

I want to Navigate to a page in the NavigationStack without re-creating a new instance or modifying NavigationStack.

Is this possible?

For Example:

NavigationStack: 
    Page1.xaml
    Page2.xaml
    Page3.xaml

Now assume I am on Page1.xaml, and want to navigate to Page3.xaml again. If i run

NavigationService.Navigate(new Uri("/Page3.xaml", UriKind.Relative));
it creates another Page1 object and navigates to that one, but i want to use the existing page object again.

Thanks

2
You want it return to the page you were and want that page to return to the that it was when you left it the first time? - robertk
yes, exactly thats what i want to mean. - mehmet6parmak

2 Answers

2
votes

Calling NavigationService.Navigate() will create a new instance of the specified page. That's the way the system works.

If you want to navigate to a page that exists in the back stack there are two options.

  1. Query the back stack and go back to the page in question. The consequences of this are that you may break the perceived back stack behaviour and the page life-cycle may also have other issues you need to work around. You will also need to communicate between the pages you are navigating to in a way that does not use the query string.

  2. Have pages fully bound to a singleton view model. i.e. Everything on a page is bound to a single instance of a view-model. If you then navigate to a new instance of that page (assuming that navigating doesn't alter/update the VM) it will have the same data, configuration, etc. as any other instances on the back stack.

Your application should follow a hub and spoke structure for navigation. Doing either of the above could break the users perception of what is expected. If you do any of the above be sure to test thoroughly with users who are familiar with the platform and understand any consequences of breaking platform conventions.

1
votes

look at the http://mvvmlight.codeplex.com/

every page is static object which is created while application is started