Nested/scoped regions?

Topics: Prism v2 - WPF 3.5
Apr 6, 2009 at 12:15 PM
I have been trying to break down one of my views (which has gotten too complicated) into multiple, smaller views. So, in the controller for that module, I have written:
IRegionManager scriptsRegionManager = regionManager.Regions[Regions.Main].Add(scriptsView, null, true);
scriptsRegionManager.Regions[Regions.ScriptSelection].Add(scriptSelectionView);
scriptsRegionManager.Regions[Regions.ScriptEditing].Add(scriptEditingView);
scriptsRegionManager.Regions[Regions.ScriptPreview].Add(scriptPreview);

This fails with a 'key not found exception', because the nested regions have not been created at the point I try to add the views to them. So, I tried a couple of other approaches:
RegionManager.SetRegionManager(scriptSelectionView, scriptsRegionManager);
RegionManager.SetRegionName(scriptSelectionView, Regions.ScriptSelection);

and

scriptsRegionManager.Regions[Regions.ScriptSelection].Add(scriptSelectionView);

Both of these also fail the same way. My views do not have any code-behind, they are just data templates, so I cannot add the nested views in any Initialize() method, and that would seem wrong anyway - I think they should be being added in the controller.

Could anyone explain to me where I am going wrong please?
Apr 6, 2009 at 3:59 PM
Hi Glenn,

What you are trying to do should just work. Could you send me a repro in a code sample?

One other approach you could take is to use the View Discovery pattern. For example, you register once that the ScriptEditing region needs a view of type ScriptEditingView. And whenever a region with name "ScriptEditing" is displayed, it's automatically populated with the view.

hope this helps,
Erwin