How to Create a Region from a Custom Region Adaptor

Topics: Prism v4 - Silverlight 4
Jun 30, 2011 at 11:59 AM

I have a situation in which I need to create a new Region from a Custom Region Adaptor and bind this new Region to a Control.

How do I do that in PRISM 4.0 using MEF?

This is the code that I found so far not sure if it is correct. 

                     AdminRightDockedSplitContainer = AdminDockSite.CreateDockedSplitContainer(DockSide.Right, DockSiteEdge.Inside, 400);
                     IRegionAdapter regionAdapter = new DockedSplitContainerRegionAdapter(Container.GetExportedValue<IRegionBehaviorFactory>());

                     var region = regionAdapter.Initialize(AdminRightDockedSplitContainer, "AdminRightDockedRegion");


 I need help to understand how to Import a reference to the Container so I can satisfy the code line... Container.GetExportedValue<IRegionBehaviorFactory>()) ... shown in above snippet.

For example how to I get a handle to the Container



public ???  Container;



Jun 30, 2011 at 3:12 PM
Edited Jun 30, 2011 at 3:17 PM
I have resolved my issue. Used the ServiceLocator to get the regionFactory.  This resolved another issue I had where my custom regions were unloading.  
It turns out this was normal behavior of the 3rd Party Docking solution that I am using.  My issue was that when I removed all ToolWindows from the docking area (which I had built a custom region for) the Dock Control automatically unloaded the Docking Area control.
As you can see by the code below, when I detect that the Docking Area has unloaded, I check if the Region has also gone, then I recreate the Docking Area and then bind the Custom Region to that Docking Area registering it back into the RegionManager.
  if (!_unloadedRightDockedSplitContainer) return;
            if (RegionManager.Regions.ContainsRegionWithName("AdminRightDockedRegion")) return;

            var regionFactory = ServiceLocator.Current.GetInstance<IRegionBehaviorFactory>();
            if(regionFactory == null) return;
            AdminRightDockedSplitContainer = AdminDockSite.CreateDockedSplitContainer(DockSide.Right, DockSiteEdge.Inside, 400);
            AdminRightDockedSplitContainer.Unloaded +=AdminRightDockedSplitContainer_Unloaded;
            var regionAdapter = new DockedSplitContainerRegionAdapter(regionFactory);
            regionAdapter.Initialize(AdminRightDockedSplitContainer, "AdminRightDockedRegion");
            _unloadedRightDockedSplitContainer = false;

Jun 30, 2011 at 4:53 PM


Thank you for share this solution with the rest of the community, as other users might benefit from knowing this.

Miguel Bronzovic