View-based navigation

Topics: Prism v4 - WPF 4
Sep 18, 2012 at 5:09 AM

Currently an ItemsControl in my shell is associated with a region. And that region registered with two views. Using a hyperlink I'm trying to navigate to a view present in another module.

But then the view to which I'm trying to navigate is not appearing on the ItemsControl. When i debugged, i could decipher that the view is indeed getting added to the ActiveViews collection but as the last entry, the first two being the other views that were previously registered.

How can i resolve the above issue and make the currently navigated to view as the active one and deactivate the other two? Please find below the code that is getting executed on the click of the Hyperlink to produce the navigation.


unityContainer.RegisterType<object, Sample>("SampleView");       

            IRegion BodyRightRegion = regionManager.Regions["BodyRightRegion"];

            BodyRightRegion.RequestNavigate(new Uri("SampleView", UriKind.Relative));



Sep 18, 2012 at 1:57 PM


Based on my understanding of your scenario, if the "SampleView" is being added to the ActiveViews collection, this view should appear on the ItemsControl. As a starting point, I believe you could check the style properties set in your ItemsControl (e.g. Height), as perhaps your view is not appearing because the control is to small for the views.

On the other hand, regarding how to deactivate the other two views, take into account that the region used for the ItemsControl control is an AllActiveRegion. This kind of region keeps all the views in it active and doesn't allow deactivation of the views. Hence, in order to avoid showing this views, you may have to add the logic to remove them from the region. For example as a possible approach you could remove all the views in it before executing the navigation to the "SampleView", e.g. like this:

 if (BodyRightRegion != null)
                foreach (object view in BodyRightRegion.Views)
                { BodyRightRegion.Remove(view); }

I hope you find this useful,

Agustin Adami

Sep 21, 2012 at 4:46 AM

Thanks Agustin, now its working like a charm.

I understand that you pointed out that the region used for the ItemsControl is an AllActiveRegion. So, is there any way change this behavior other than manually removing all the views before navigating to a new one?

Sep 25, 2012 at 12:47 PM


As far as I know Prism only provides the RegionMemberLifetimeBehavior which could be used to achieve this kind of scenarios. This behavior  is responsible for determining if an item should be removed from the region when it is deactivated, which could be used to remove the view when navigating away from it. The problem with this approach is that it requires that your region allows deactivation of the views, in which case you could consider changing your region container to be a SingleActiveRegion.

As an alternative, I believe you could also implement you own region behavior which for example could monitor changes in the Views collection of the region, and remove previous views from the region based on a custom logic depending on the requirements of your scenario. For more information about region behaviors you could check the following sections of the Prism documentation:


Agustin Adami