问题描述
我正在用Prism编写应用程序。我有一个用户控件,其中包含两个< ContentControl>
控件。这些都分配了区域。用户控件托管在 Window
窗口中,该窗口使用 ShowDialog()
显示。
我正在使用视图发现将一个视图添加到一个区域,另一个视图则是将视图注入该区域。视图发现工作正常。但是,当我尝试引用其他区域以注入视图时,出现异常:
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
经理不包含 MyRegion 区域。
当我在RegionManagers区域中查看时,我要注入的视图都不存在
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.
我与Shell不在同一个窗口是否重要?我以为只有一个RegionManager,但是必须有两个,我的视图发现才能继续起作用...?还是因为在应用程序生命周期的后期创建了两个新区域?还是因为新区域不在我的MainRegion内?
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?
编辑:
它看起来像创建了Region,但是找不到RegionManager的实例,因此不会添加它。有任何线索吗?
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?
推荐答案
现在已排序。我需要在presenter类的构造函数中注册区域经理。
这样,在新窗口中的区域就可以找到我的全球区域经理。
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(以DependencyObject,regionManager的形式查看);
这篇关于在RegionManager中找不到区域(使用PRISM)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!