Adding a module to a region from the Shell

Topics: Prism v4 - WPF 4
Dec 2, 2010 at 1:37 PM

I am able to access the RegionManager from the ModuleInit of a module.

Using this I can add the module to a region.

However I cannot access the RegionManager from the Shell.

How do I add a module to a region from the Shell?

 

Dec 2, 2010 at 3:20 PM

If you don't have a shellviewmodel it might help things. At least that is how I get other things into the ShellView of my application.

Developer
Dec 2, 2010 at 8:02 PM

Hi,

Firstly, take into account that you can add views to regions, not modules. Views are visual components, while modules are functional unities. You can read more about this in this thread.

That said, it isn´t a recommended practice to add views into regions from the shell itself. This is because the purpose of adding views to regions is to allow loosely coupled components (modules) to add visual components (views) into an integrated layout. So, it could be better practice to place the views in separate modules. If you need to place a visual component in the shell, which will not come from a Module then you could simply add this component in the XAML file of your shell. You can read more about this, in this chapter from Prism v4 MSDN documentation.

As for accessing the RegionManager from the Shell, you could implement constructor injection in your shell’s code behind, and inject the RegionManager class. For example, you can read about constructor injection in MEF here, and in Unity here.

However, if your scenario requires performing some action in a specific region from within the shell, you will need to handle the RegionManager’s Region property’s CollectionChanged event in your Shell class. This is because after the initialization of the Shell, the regions within are not instantly created. In this post you can see an example on how to detect Region´s CollectionChanged event.

I hope you find this helpful.

Guido Leandro Maliandi
http://blogs.southworks.net/gmaliandi

Dec 3, 2010 at 11:46 AM

Thanks for the clear explanation :)

Mar 25, 2011 at 6:58 AM

Hi Guido,

The link shared does not work anymore! Could you please share the link once again.

Thanks a lot,

Indrasis

Mar 25, 2011 at 6:58 AM

Hi Guido,

The link shared does not work anymore! Could you please share the link once again.

Thanks a lot,

Indrasis

Developer
Mar 28, 2011 at 3:43 PM

Hi Indrasis,

The thread I've shared with you in the previous post can be found in the following address:

http://compositewpf.codeplex.com/discussions/235477

I hope you find this helpful.

Guido Leandro Maliandi
http://blogs.southworks.net/gmaliandi