Nested Regions

Oct 11, 2012 at 7:38 AM
Edited Oct 12, 2012 at 11:26 AM

Hi,

Here is my strategy,

I have a ContentView inside my module which is acting as a container for it's nested regions.
The below code was working for me when it was just a single region, but I decided to divide it up.
I was using Interfaces for registering types, would be no matter change them with the real contents, That's no matter here.

I know the piece of code I provided have got some errors,
please help me as I think using these Nested regions could clean the code more and it would structure better.

I'm Using Unity  .

 

Inside the ContentView

// Inside a grid

            <DockPanel Grid.Column="0" prism:RegionManager.RegionName="Left" />
           
<DockPanel Grid.Column="0" prism:RegionManager.RegionName="Right" />

Adding the LeftView will cause an error.

Running the code will give this error :
{"An exception occurred while creating a region with name 'Left'. The exception was: System.Collections.Generic.KeyNotFoundException:
The IRegionAdapter for the type System.Windows.Controls.DockPanel is not registered in the region adapter mappings. You can register an IRegionAdapter for this control by overriding the ConfigureRegionAdapterMappings method in the bootstrapper.\r\n    

I know the code is wrong, but don't know the correct way dealing with these Nested regions.

How should I change the code to do the job ?
Should I threat Nested Regions the same as my container region ?
Is the code ordered Correctly ? (Their precedence)

Developer
Oct 11, 2012 at 6:23 PM

Hi,

As described in the exception, the problem you are experiencing is that there is no RegionAdapter registered for the type DockPanel. This is because Prism does not support Regions based on DockPanels as out of the box.

Basically, when setting a control as a Region, Prism will search inside its RegionAdapterMappings in order to find a RegionAdapter that is suitable for that control. As out of the box, Prism provides RegionAdapters for the following types:

  • SelectorRegionAdapter: To create Regions based on controls that inherit from the Selector class.
  • ItemsControlRegionAdapter: To create Regions based on controls that inherit from the ItemsControl class.
  • ContentControlRegionAdapter: To create Regions based on controls that inherit from the ContentControl class.
  • TabControlRegionAdapter: To create Regions based on TabControls (only in Silverlight, in WPF this adapter is not required.)

As the DockPanel controls does not inherit from any of the aforementioned controls, Prism does not have a RegionAdapter for it, and the aforementioned exception is raised. In order to use a DockPanel as a region, you would need to develop your own custom RegionAdapter from it and register it in RegionAdaptersMappings. You can find more information about RegionAdapters in the following section of Prism's documentation:

Damian Cherubini
http://blogs.southworks.net/dcherubini

Oct 12, 2012 at 11:27 AM

You are right, Thanks