I have silverlight 4 application with PRISM 4, I’m using MEF.
My Shell defines one main region in which modules are loaded, I want modules to have their own RegionManager, so regions that they define are places in local RegionManager instead of global. And I want this local RegionManager to be resolved by container (for type IRegionManager) when inside the module.
However the method from documentation:
IRegion detailsRegion = this.regionManager.Regions["DetailsRegion"];
View view = new View();
bool createRegionManagerScope = true;
IRegionManager detailsRegionManager = detailsRegion.Add(view, null,
createRegionManagerScope);
Doesnt work for me, when resolving IRegionManager from inside child view I still get GlobalRegionManager.
I was in the same situation as you, I had a nested region manager, but all of the child views were still getting the global region manager. I came up with what I consider a reasonable solution.
First I define an interface:
Then I setup a
RegionBehaviorlike so:Then apply this to all regions in your bootstrapper:
Then all you have to do is implement
IRegionManagerAwareon your view/viewmodel, probably like so:Then when this view is added to a region, the behaviour will correctly set the
RegionManagerproperty to the currently scoped region manager.