Cannot find Region in RegionManager (using PRISM)

戏子无情 提交于 2019-12-20 01:38:14

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/2162391/cannot-find-region-in-regionmanager-using-prism

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!