Cannot find Region in RegionManager (using PRISM)

2019-02-24 04:38发布

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?

标签: wpf Prism cab
1条回答
Bombasti
2楼-- · 2019-02-24 05:01

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);

查看更多
登录 后发表回答