Nested Regions

Topics: Prism v2 - WPF 4
Mar 15, 2011 at 1:57 PM

Can anyone tell me why this doesn't work?

<Window x:Class="PrismRegions.View.MainView"
        Title="Main View" Height="300" Width="300">
        <Menu DockPanel.Dock="Top" cal:RegionManager.RegionName="MainMenu">
            <MenuItem Header="_File">
                <MenuItem Header="E_xit" Command="{Binding ExitCommand}" />
            <MenuItem Header="_Edit" cal:RegionManager.RegionName="EditMenu" />
        <ContentControl />

Clearly prism doesn't like regions declared within regions.

Incase you've never tried it, if you try and refer tothe EditMenu region in code it doesn't exist.

So what is the recommended way of achieving nested regions?

In summary my goals are:

  • Module 1 might want to inject an item onto the Edit menu
  • Module 2 might want to inject a whole new menu onto the menu bar.


Many thanks,


Mar 15, 2011 at 4:06 PM
Edited Mar 15, 2011 at 5:11 PM


I've reproduced the scenario you've mentioned and found that, if you try to add a region directly inside another region, the ItemsControlRegionAdapter will fail to attach the RegionManagerProperty to the child region, thus making the RegionManagerRegistrationBehavior fail to register it into the RegionManager.

This happens because, when you create a region in an ItemsControl that already had some children in the Items collection, the ItemsControlRegionAdapter will clear the Items property, add them as views to the newly generated IRegion, and then set the control's ItemsSource to the IRegion's Views property. However, at the moment this is done, the RegionManagerRegistrationBehavior will have not registered the parent region in the RegionManager, hence its RegionManager property will be null. Therefore, since the Region's InnerAdd method sets the RegionManager.RegionManager attached property into the View that gets added to a region, the view (which in your case is itself a region) won't have its RegionManager property set.

The recommended approach for having nested regions is to add a view containing the nested region into the main region. For example, if you had your Menu region like this:

<Menu DockPanel.Dock="Top" cal:RegionManager.RegionName="MainMenu">
            <MenuItem Header="_File">
                <MenuItem Header="E_xit" Command="{Binding ExitCommand}" />

You could programatically add the MenuItem region (in another module, for example):


IRegionManager manager = ServiceLocator.Current.GetInstance<IRegionManager>();
var menuItem = new MenuItem() { Header = "EditMenu" };


That way, you would avoid the timing issue I've described.

I hope you find this helpful.

Guido Leandro Maliandi

Jan 16, 2012 at 9:05 PM

I'm experiencing a similar issue where I have a region "ShellRegion" in the ShellView, and I want to have another region in one of its nested views, then use the region manager to RequestNavigate the nested view.

What I've tried is XAMLy attributing both the controls that are used for regions with the prism RegionName attached prop.

When I try to refer to the child region, I get an exception that it doesn't exist.

Just to make clear I want to have a "MainRegion" that is a descendant of "ShellRegion", then I want to RequestNavigate a view inside the child region ("MainRegion")

Jan 17, 2012 at 12:11 AM
Edited May 20, 2012 at 12:43 AM

Found answer:

The nested region is added later at runtime after the shell region was registered in the Bootstrapper, and thus has to be explicitly re-registered, I've added the following code to the View that contains the child region ("MainRegion"):


public MainView(IRegionManager regionManager, MainViewModel vm)
  DataContext = vm;
  RegionManager.SetRegionManager(mainRegionControl, regionManager);

Now everything works perfect.

Jun 6, 2013 at 7:46 PM
I am having similar issue.

I am using a TabControl - regionName is set as "TabRegion" (hence ItemsControlRegionAdapter comes in play) and I add a tabItemView (with nested regions in it) to my TabItem.


I observe that my tabItemView in tabitem has RegionManagerProperty set to null.

If I use scoped regions for each tabItem using the following code:

then I am able to see _scopedRegionManager in my tabItemView using the following:
IRegionManager _rm=RegionManager.GetRegionManager(tabItemView);

But any view defined inside the regions in tabItemView returns null for RegionManager property.

I tried the solution proposed by GuidoMaliandi and weitzhandler but to no avail.

Could you kindly tell me how to get the RegionManager property in views within nested regions (this seems a generic issue with nested regions and not the scoped regions)?
Please let me know if I could provide more information.

Jun 6, 2013 at 9:45 PM

Have you tried using the RegionManagerAwareBehavior shown in my blog post?
I believe it could be helpful to work around your problem. Basically, after registering the region behavior in the Bootstrapper, any view or view model that implements IRegionManagerAware will find its RegionManager property (the one declared in the interface) set with their corresponding RegionManager each time they are injected in a Region. This should also include any view / view model injected in nested regions.

I hope this helps,

Damian Cherubini
Jun 7, 2013 at 8:38 PM
Edited Jun 7, 2013 at 8:40 PM
Hi Damian,

Thanks for your response. It was indeed very helpful as always.
I did look at the RegionManagerAwareBehavior class, but I could get pass the issue by just using IRegionManagerAware interface of yours and setting the following in the view which has nested regions:
prism:RegionManager.RegionManager="{Binding TheRegionManager}"

<UserControl x:Class="UC1"
        <ContentControl prism:RegionManager.RegionName="TOP_REGION"  
                        prism:RegionManager.RegionManager="{Binding TheRegionManager}"/>
        <ContentControl prism:RegionManager.RegionName="BOTTOM_REGION" 
                        prism:RegionManager.RegionManager="{Binding TheRegionManager}"/>
We are using ViewModel First apparoach and every viewModel implements IRegionManagerAware interface. In child view's OnVisualParentChanged method we do the following:
        protected override void OnVisualParentChanged(DependencyObject oldParent)
            if (this.MyViewModel != null)
                MyViewModel.TheRegionManager = RegionManager.GetRegionManager(this);
                // If TheRegionManager property is set on content control, then use this.Parent:
                if (MyViewModel.TheRegionManager == null && this.Parent != null)
                    MyViewModel.TheRegionManager = RegionManager.GetRegionManager(this.Parent);
We are in the process of studying the RegionManagerAwareBehavior and will probably move to it later (half hoping that prism's next release will have this fixed :-) ).