Navigation Help

Topics: Prism v4 - WPF 4
May 14, 2014 at 6:55 PM
Edited May 14, 2014 at 6:58 PM
I cannot seem to get navigation to work with unity.

I register my view:
this.regionViewRegistry.RegisterViewWithRegion("MIPRegion", typeof(Views.Designator));

Then I try to make the request:
this.regionManager.RequestNavigate("MIPRegion", new Uri("Designator", UriKind.RelativeOrAbsolute));

However, OnNavigatedFrom in this View Model NEVER gets called.

If I have one region that 10 different views can display in, do I have to call RegisterViewWithRegion() for all of those views and that region for navigation to work? And if so, how do I prevent the view from being activated with RegisterViewWithRegion. Whenever I use RegisterViewWithRegion, it automatically displays the view in it. Thanks for any help.

Edit: I forgot to mention, a System.Object is getting added to the region after RequestNavigate() gets called. But that is all that happens.
May 14, 2014 at 7:01 PM
Edited May 14, 2014 at 7:03 PM
Fixed:

this.container.RegisterType<Object, Views.CheckedOutIncidentMIP>("WORKVIEW");

I had to override the Object type.

The only issue is even though navigation is working, "OnNavigatedFrom" Is not getting called.
Marked as answer by mathius25 on 5/14/2014 at 11:33 AM
May 14, 2014 at 7:13 PM
Edited May 14, 2014 at 7:33 PM
I have nested regions, so I am wondering if that is the issue.
May 14, 2014 at 7:52 PM
Hi Mathius,

First, there would not be neccessary to use RegisterViewWithRegion before executing Navigation. If the View you would like to Navigate to is not previously registered, then the Region would add it to its View list. And in order to prevent activation of Views when they would get registered, you could use the Region's Add() method.
Moreover, for the OnNavigatedFrom() and OnNavigatedTo() methods getting called, they ViewModel would need to implement INavigationAware interface. This way, the INavigationAware ViewModels are resolved when navigation occurs, and its OnNavigatedFrom() method is called.

Based on my understanding, the "MyViewModelBase" class would be implementing INavigationAware so the OnNavigatedFrom() method is called. But what derived types would you need for calling?

You can find more information about View-Switching Navigation in the following MSDN Prism Guide chapter:

I hope this helped you,
Regards.

Gabriel Ostrowsky
https://blogs.southworks.net/gostrowsky
May 15, 2014 at 6:30 PM
Awesome. Thanks a lot!