问题描述
我正在使用 IRegionManager
来加载和导航至视图,我在将内容加载到引导程序类已加载的主视图中的主区域中没有问题,但是无法将内容加载到内部区域中在我加载的视图中,区域管理器似乎没有注册这些区域.
I am using IRegionManager
to load and navigate to views, I have no problem loading content to my main region in my main view which is loaded with my bootstrapper class but I cant load content to regions inside my loaded views, the region manager does not seem to be registering these regions.
我的引导程序类:
protected override DependencyObject CreateShell()
{
return this.Container.Resolve<MainWindowView>();
}
protected override void InitializeShell()
{
Application.Current.MainWindow.Show();
}
protected override void ConfigureContainer()
{
base.ConfigureContainer();
this.Container.RegisterTypeForNavigation<DocumentView>();
this.Container.RegisterTypeForNavigation<EmailView>();
this.Container.RegisterTypeForNavigation<WorkTypeSelectionView>();
}
DocumentView
是具有另一个区域的用户控制,触发命令时运行的方法是这样的:
the DocumentView
is user control with another region the method that runs when the command is triggered is this:
private void ViewEmailAction()
{
NavigationParameters parameters;
parameters = new NavigationParameters();
parameters.Add(nameof(this.CurrentEmail), this.CurrentEmail);
this.regionManager.Regions[this.EmailRegion].RequestNavigate(nameof(EmailView), parameters);
}
这引发并带有消息区域管理器不包含EmailRegion区域."的异常.
提前谢谢!
推荐答案
这里发生了两种不同的事情:
There are two different things going on here:
UserControls:这应该不会有任何问题.您可能会尝试导航到尚未加载的View中定义的区域.确保已加载区域后导航至该区域.在ViewModel构造函数内部导航是此问题的最大来源之一.如果您想将示例发布到GitHub,我可以看看.
UserControls:This should work with not issues whatsoever. Chances are that you are trying to navigate to a region that is defined in a View that hasn't been loaded yet. Make sure you are navigating to a region after it has been loaded. Navigating inside of ViewModel constructors is one of the biggest sources of this problem. If you want to post your sample to GitHub, I can take a look.
ControlTemplates:这是棱镜中的一个已知问题.这是您的解决方法:
ControlTemplates:This is a known issue in Prism. Here is your fix:
这篇关于如何在RegionManager中的用户控件或控件模板中注册区域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!