How to place by many Regions in XAML?

Topics: Prism v1, Prism v2 - Silverlight 2, Prism v2 - Silverlight 3, Prism v2 - Silverlight 4, Prism v2 - WPF 3.5, Prism v2 - WPF 4, Prism v4 - Silverlight 4, Prism v4 - WPF 4
May 31, 2011 at 11:35 AM

Is it possible?

    <ItemsControl x:Name="tb1" cal:RegionManager.RegionName="{x:Static inf:RegionNames.MainToolBarRegion}" />
    <ItemsControl x:Name="tb2" cal:RegionManager.RegionName="{x:Static inf:RegionNames.MainToolBarRegion}" />
Why I don't can't do it? 

May 31, 2011 at 11:52 AM



what do you want to achieve with this ?

May 31, 2011 at 12:17 PM

The architecture my app suggests a few identical controls. I want these controls to store in modules. Then I show they in Shell.

May 31, 2011 at 3:43 PM


The RegionManager does not allow to add regions with the same name. Therefore, you should identify your regions with unique names.

If you'd like to show a view twice, you could use scoped regions. By using scoped regions, when you add a view to a region, you create a scoped region manager for the regions that lie inside that view. Therefore, if you create multiple instances of a view that holds a region inside, multiple instances of that region (with the same name) are generated, but inside separate region managers. However, when you register a view into that region (by using the view discovery approach), the view gets added to all of them (as soon as they are added to the visual tree).

You could read more about scoped regions here.

I hope you find this helpful.

Guido Leandro Maliandi

May 31, 2011 at 3:59 PM
Edited May 31, 2011 at 4:01 PM

GuidoMaliandi, thanks a lot. But I think it's defect of prism. Becose I can't easyly added region in xaml.

May 31, 2011 at 4:06 PM
Edited May 31, 2011 at 4:06 PM

If you consider that behavior undesirable, you could create a work item in the issue tracker, so that the Prism team considers modifying it for a future version.


Guido Leandro Maliandi

May 31, 2011 at 6:49 PM
Edited May 31, 2011 at 6:50 PM

Now I'm doing so

            <ContentControl x:Name="mwr" MinHeight="100"  />
            <ContentControl x:Name="mwr2" MinHeight="100"  />
      IRegionManager regionManager = ServiceLocator.Current.GetInstance<IRegionManager>();
      RegionManager.SetRegionManager(this.mwr, regionManager);
      RegionManager.SetRegionName(this.mwr, "ModuleWorkspaceRegion");

      RegionManager rm = new RegionManager();
      RegionManager.SetRegionManager(this.mwr2, rm);
      RegionManager.SetRegionName(this.mwr2, "ModuleWorkspaceRegion");

All work. But, is it right way? May be in future I get any problem?

Thank you!

May 31, 2011 at 8:02 PM


Your approach seems to be valid, as it should produce similar results to using scoped regions.


Miguel Bronzovic