How to create a tabcontrol with dynamic region names.

Topics: Prism v4 - WPF 4
Jan 5, 2011 at 2:12 PM
Edited Jan 6, 2011 at 9:15 AM

I want to create a shell that can host views of different applications.

We also want the ability to add two tabs for entity Order with two different orders (same view)

I can add a Tab + ContentControl to the Tabs collection but how to dynamically add a region (name like "Order 1" and "Order 2").

After this I can register a view with this new region.

Jan 5, 2011 at 2:58 PM


As the RegionManager.RegionName attached property is a DependencyProperty, you could bind its value to a property in your ViewModel, or to any other property that could help you achieve your scenario.

After the regions have been created, you could add views to them normally. Take into account that there can't be two regions with the same name in a single region manager, but you can have regions with the same name in scoped region managers. You can read more about this in this chapter from the Prism MSDN documentation (specifically in the "Creating Multiple Instances of a Region" section).

On a different note, as explained in this thread, it's not possible to load modules (and the views and services that belong to them) into separate AppDomains out of the box. You can, however, host views that come from different assemblies in your shell.

I hope you find this helpful.

Guido Leandro Maliandi

Jan 6, 2011 at 9:21 AM


Thanks for your reply.

I have an other question about adding the DependencyProperty to a ContentControl in code (C#)

What do I have to do after creating a new ContentControl to add a region to that ContentControl?

I hope you can help me.

Regards Rob

Jan 6, 2011 at 2:33 PM

Hi Bob,

Once a Control with the RegionManager.RegionName set is loaded into the visual tree, its corresponding region is created and registered automatically. There are two behaviors responsible for this:

DelayedRegionCreationBehavior: "Behavior that creates a new IRegion, when the control that will host the IRegion is added to the VisualTree. This behavior will use the RegionAdapterMappings class to find the right type of adapter to create the region. After the region is created, this behavior will detach."

RegionManagerRegistrationBehavior: "Subscribes to a static event from the RegionManager in order to register the target IRegion in a IRegionManager when one is available on the host control by walking up the tree and finding a control whose RegionManager.RegionManagerProperty property is not null."

After doing so, you can start adding views to the regions following any of the approaches mentioned in the UI Composition or Navigation chapters.

I hope you find this helpful.

Guido Leandro Maliandi