Region not found

Topics: Prism v4 - WPF 4
Jun 28, 2011 at 5:24 PM
Edited Jun 28, 2011 at 5:26 PM

Hi,

I have a Shell which contains one region "MainRegion" as shown below.

 

<!-- Shell -->
<Window x:Class="PrismLearning.Shell"
.....
<ContentControl x:Name="ContentView" prism:RegionManager.RegionName="MainRegion"/>

 

 

Then I have one View "CustomerMainView" which successfully loads into "MainRegion" as shown below. The "CustomerMainView" has only one region named "CustomerRegion"

 

<!-- CustomerMainView -->
<UserControl x:Class="CustomerModule.CustomerMainView"
.....
<ItemsControl prism:RegionManager.RegionName="CustomerRegion"/>

 

 

Now when I try to load a view into "CustomerRegion" above, I get region not found error in RegionManager. Here is the relevant code that tries to load view the in "CustomerRegion"

 

            CustomerViewModel custViewModel = 
                ServiceLocator.Current.GetInstance<CustomerViewModel>();

            _regionManager.Regions["CustomerRegion"].Add(custViewModel);
            _regionManager.Regions["CustomerRegion"].Activate(custViewModel);

 

Any idea why the "CustomerRegion" is not populated in the Regions property of RegionManager?

regards,

Nirvan.

Developer
Jun 28, 2011 at 7:19 PM
Edited Jun 29, 2011 at 3:27 PM

Hi Nirvan,

We've examined the repro sample you've uploaded (in this thread), and found that your issue could be happening because you're defining your region inside a DataTemplate. Currently, regions defined inside DataTemplates aren't added to the RegionManager, because the FindRegionManager method in the RegionManagerRegistrationBehavior cannot locate the RegionManager attached property in DataTemplates (possibly due to the fact that they have no parent in the logical tree).

You can find more information on the subject in the following thread:

I hope you find this helpful.

Guido Leandro Maliandi
http://blogs.southworks.net/gmaliandi