Load a single view in the multiple region

Topics: Prism v4 - Silverlight 4, Prism v4 - WPF 4
Jun 24, 2011 at 10:41 AM
Edited Jun 24, 2011 at 10:43 AM


How to load the single view into the multiple region of the shell in the Silverlight/WPF using PRISM and MEF.


Assume having two regions "MainRegion" and "SubRegion" in the shell. I want to load the "OrderView " from the module in the 2 regions.



Jun 24, 2011 at 1:58 PM

Hi Mahesh,

Depending on the approach you're using for adding views to regions, you could do the following:

If you're using View Discovery, you could register the view in both regions, for example:

ServiceLocator.Current.GetInstance<IRegionViewRegistry>().RegisterViewWithRegion("MainRegion", typeof(OrderView));

ServiceLocator.Current.GetInstance<IRegionViewRegistry>().RegisterViewWithRegion("SubRegion", typeof(OrderView));

On the other hand, if you're using View Injection, you could add the view to both regions, for example:


var viewInstance1= ServiceLocator.Current.GetInstance<OrderView>();

var viewInstance2= ServiceLocator.Current.GetInstance<OrderView>();




Note that you should make sure that you're adding different instances of the view into the different regions (because the same instance of a visual component cannot be added twice in the visual stree), so you should make sure that you have registered your view as a non shared instance (by either adding the PartCreationPolicy attribute with the CreationPolicy.NonShared value in MEF, or registering the type without specifying a ContainerControlledLifetimeManager in Unity).

You can read more about the UI Composition mechanisms in this chapter, and you can read more about Dependency Injection in Prism in this chapter from the MSDN documentation.

I hope you find this helpful.

Guido Leandro Maliandi

Jul 5, 2011 at 10:36 AM


Thanks a lot. It works fine.