Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find Region in RegionManager (using PRISM)

Tags:

wpf

prism

cab

I'm writing an application in Prism. I have a user control and contains two <ContentControl> controls. These both have Regions assigned to them. The usercontrol is being hosted in a Window that is being shown using ShowDialog().
I'm adding the one of my views to a region using view discovery and the other I want to inject the view into its region. The view discovery works fine. However when I try and reference the other region to inject the view I get the exception:

KeyNotFoundException
The region manager does not contain the MyRegion region.

When I look in the RegionManagers regions neither the one that I'm trying to inject the view exists or the one being that's using view discovery.

Does it matter that I'm in a different window to the Shell? I thought there was only one RegionManager, but there must be two for my view discovery to still be working...? Or is it because I have two new regions being created later in the applications life cycle? Or is it because the new regions aren't inside the my MainRegion?

EDIT:
After doing some digging it looks like the Region is created but it can't find an instance of the RegionManager so it doesn't get added. Any clues?

like image 990
Jon Mitchell Avatar asked Feb 28 '23 16:02

Jon Mitchell


1 Answers

Sorted now. I needed to register the region manager in the constructor of my presenter class.
That way the regions in my new window could find my global region manager.

RegionManager.SetRegionManager(view as DependencyObject, regionManager);

like image 115
Jon Mitchell Avatar answered Mar 07 '23 04:03

Jon Mitchell