Switch between Views in different Modules using Prism and Unity

Topics: Prism v4 - WPF 4
Nov 12, 2012 at 1:12 PM
Edited Nov 12, 2012 at 1:25 PM

I am making a proof of concept WPF application with Prism 4 and Unity, but I run into some basic problems. 

In our solution we have the following projects:


Having followed some tutorials, explored some examples and searched the internet, I wasn't able to find a suitable answer to a very rudimentary question; how can I switch between two views in different DLL's.

The first view (ModuleAView) is loaded in the Initialize method of ModuleA:


public void Initialize() { 
regionManager.RegisterViewWithRegion("MainRegion", typeof(Views.ModuleAView));}


When I click in ModuleAView (or on a button in ModuleAView) I want to switch to ModuleBView.       


private void SomeEventInModuleAView(object sender, RoutedEventArgs e) { 
	Uri viewNav = new Uri("ModuleBView", UriKind.Absolute);	regionManager.RequestNavigate(RegionNames.MainRegion, viewNav);� � 

Obviously this won't work, since ModuleA doesn't know where to find ModuleBView. I have read about changing the URI with pack/application/component etc, but I can't seem to make it work.    I was thinking something like this:       


Uri("pack://application:,,,/AppName.Modules.ModuleB;component/Views/ModuleBView.xaml", UriKind.Absolute);

Since loading modules from different assemblies is one of the purposes of Prism, I think it's strange that there aren't any examples in the Prism download to show how this works. 

Nov 12, 2012 at 3:57 PM


Based on my understanding of your scenario, it seems that you are not registering the ModuleBView to be used with navigation.

Basically, when performing a navigation request in a region, Prism will try to construct the corresponding view through the dependency injection container of your application (in this case Unity) using the view's name passed in the Uri. Hence, if the view is not registered with that name in the dependency injection container, Prism would not be able to resolve it and the navigation request would fail.

In order for a view to be used with navigation in Unity you need to register it like this:


For example, you can register the ModuleBView like this:

// Module B
public void Initialize()

Doing this, you can navigate to different views in different modules without needing for the modules to know each other or their assemblies.

You can find more information about this in the following chapter of the Prism documentation:

I hope you find this useful,

Damian Cherubini

Nov 13, 2012 at 6:15 AM

Hi Damian,

That definitely did the trick! Thanks for this clear explanation.

I have bought the book, but I guess I need to shuffle the chapters a bit ;-)