PRISM - 子区域视图的重用 - 可以做到吗?
我是一个 PRISM 新手,但我已经阅读了帮助文档,似乎无法找到如何实现以下功能(这是一个 WPF 应用程序)
我有一个 Shell
(窗口)有 2 个区域,称为“region1”和“region2”。 在我唯一的模块的 Initialize
方法中,我向每个区域注册相同的视图:
regionViewRegistry.RegisterViewWithRegion("Region1", typeof(View1));
regionViewRegistry.RegisterViewWithRegion("Region2", typeof(View1));
当我运行它时,此时一切正常,因为它创建了 View1 的 2 个单独实例
,并在每个区域放置一个。
现在在 View1
中,我已经声明了自己的区域来注入小型子视图
<ItemsControl Name="MainRegion" cal:RegionManager.RegionName="MainRegion" />
现在,当我运行非常简单的 PRISM 应用程序时,我收到以下异常消息:
“具有给定名称的区域已经 注册:MainRegion"
这表明如果该视图声明了自己的区域,我就不能拥有同一视图的多个实例。
这是正确的吗?
似乎是一个巨大的限制。
我希望我的应用程序是高度模块化的,并且让视图自行组成其他观点(通过地区)等。
或者我误读了文档?
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)
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));
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.
Now in View1
I have declared its own region for injecting small child views
<ItemsControl Name="MainRegion" cal:RegionManager.RegionName="MainRegion" />
Now when I run my very simple PRISM app I get the following exception message:
"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.
Is this correct ?
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.
Or have I mis-read the documentation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 RegionScope 将 shell 级区域与模块视图创建的区域分开。您在没有范围的情况下创建的任何区域都是“全局”的,并且不支持在同一范围内拥有两个具有相同名称的区域。
您可以在这篇 MSDN 文章中阅读有关区域范围的更多信息:
http://msdn.microsoft.com/en-us/magazine/cc785479.aspx#id0090126< /a>
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.
You can read more about Region Scopes in this MSDN article:
http://msdn.microsoft.com/en-us/magazine/cc785479.aspx#id0090126