Getting all RegionManagers including subregions - regions within regions

Topics: Prism v2 - WPF 4, Prism v4 - WPF 4
Aug 31, 2012 at 5:01 PM

I have a situation in which I would like to access all the regions in a shell, including sub regions. The reason is fairly simple, I would like to get notified whenever a view/viewmodel is loaded in to any of these regions, including sub regions, so that I could take some necessary actions.

Is there a way to achieve this?

Thanks,
Sudarsan Srinivasan

Developer
Aug 31, 2012 at 6:53 PM

Hi,

As far as I know, obtaining all the RegionManagers of the application is not supported in Prism as out of the box.

As a possible approach to achieve this I believe you could create a Shared Service where you could add the RegionManagers as they are created. Then, when you need to access all the RegionManagers you could consume the service to obtain them.

You can find more information about Shared Services in the following section of the Prism documentation:

Take into account that this could create memory leaks if unused RegionManagers are being referenced by the service, causing them to not be garbage collected. As a possible approach to avoid this, you could store the references to the RegionManagers inside the service using Weak References.

You can find more information about Weak References in the following article on MSDN:

Regards,

Damian Cherubini
http://blogs.southworks.net/dcherubini