棱镜-重用带有子区域的视图-可以完成吗? [英] PRISM - Reuse of Views With Child Regions - Can It Be Done?

查看:69
本文介绍了棱镜-重用带有子区域的视图-可以完成吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是PRISM的新手,但是我已经阅读了帮助文档,似乎无法找到实现以下目标的方法(这是WPF应用程序)

I'm a bit of a PRISM newbie, but I've read the help documentation and can't seem to find out how to achieve the following (this is a WPF application)

我有一个Shell(窗口),其中有2个区域,分别称为"region1"和"region2". 在我唯一的模块的Initialize方法中,我正在每个区域注册相同的视图:

I have a Shell (Window) that has 2 regions called 'region1' and 'region2'. in the Initialize method of my one and only module, I am registering the same view with each region:

regionViewRegistry.RegisterViewWithRegion("Region1", typeof(View1));
regionViewRegistry.RegisterViewWithRegion("Region2", typeof(View1));

当我运行它时,这一切都很好,因为它创建了两个单独的View1实例,并在每个区域中放置了一个.

and when I run it everything is OK at this point as it creates 2 individual instances of View1, and places one in each region.

现在在View1中,我已经声明了自己的区域以注入小的子视图

Now in View1 I have declared its own region for injecting small child views

<ItemsControl Name="MainRegion" cal:RegionManager.RegionName="MainRegion" />

现在,当我运行非常简单的PRISM应用程序时,会收到以下异常消息:

Now when I run my very simple PRISM app I get the following exception message:

具有给定名称的区域已经 已注册:MainRegion"

"Region with the given name is already registered: MainRegion"

这表明如果同一视图声明了自己的区域,则我不能拥有该视图的多个实例.

which suggests that I cannot have multiple instances of the same view if that view declares its own regions.

这是正确的吗?

似乎有很大的局限性.

我希望我的应用程序具有高度的模块化,并使其视图由其他视图组成(通过区域)等.

I want my application to be highly modular, and to have view compose themselves of oother views (via regions) etc.

还是我误读了文档?

推荐答案

您可以使用RegionScope通过模块视图创建的区域创建外壳程序级区域的分隔.您创建的没有范围的任何区域都是全局"区域,并且不支持在同一范围内具有两个具有相同名称的区域.

You can create a separation of shell-level regions with regions created by module views by using RegionScope. Any region you create without a scope is "global" and having two regions with the same name in the same scope isn't supported.

您可以在此MSDN文章中阅读有关区域范围的更多信息: http://msdn.microsoft.com/en-us/magazine/cc785479.aspx#id0090126

You can read more about Region Scopes in this MSDN article: http://msdn.microsoft.com/en-us/magazine/cc785479.aspx#id0090126

这篇关于棱镜-重用带有子区域的视图-可以完成吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆