PRISM - 重用子区域的视图 - 可以做吗? [英] PRISM - Reuse of Views With Child Regions - Can It Be Done?
问题描述
我是 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
的 2 个单独实例,并在每个区域放置了一个.
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.
这是正确的吗?
似乎是一个巨大的限制.
seems like a huge limitation.
我希望我的应用程序高度模块化,并让视图由其他视图(通过区域)等组成.
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
这篇关于PRISM - 重用子区域的视图 - 可以做吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!