简体   繁体   English

在包含相同区域的多个视图之间共享棱镜视图

[英]Sharing Prism Views between multiple Views that contain the same region

I am trying to achieve the following pattern where the ContentRegion can have either ModuleShellView or Module2ShellView loaded/Active at any moment in time. 我正在尝试实现以下模式,其中ContentRegion可以随时加载/激活ModuleShellView或Module2ShellView。

Module2ShellView has no reference to View1 but cause View1 has been registered to Region1 it is loaded into the Module2ShellView when that view is loaded into the ContentRegion but I want both ModuleShellViews to share the same instance of View1. Module2ShellView没有对View1的引用,但是由于View1已注册到Region1,所以当该视图加载到ContentRegion中时,它已加载到Module2ShellView中,但是我希望两个ModuleShellViews共享同一View1实例。

I want to be able to switch between both ModuleShellViews 我希望能够在两个ModuleShellViews之间切换

MainShell
--ContentRegion
----ModuleShellView
------Region1
--------View1
----Module2ShellView
------Region1
--------View1

Based on my understanding, you would want View1 instance to be available for both ModuleShellViews . 根据我的理解,您希望View1实例可用于两个ModuleShellViews One way to do this is to register View1 as Singleton in the Container so each time View1 is loaded, the container will return always the same instance. 要做到这一点的方法之一是注册View1辛格尔顿容器中 ,以便每次View1加载,容器将总是返回同一个实例。

You can find more related information of View Registration on the following Prism guide chapter: 您可以在以下棱镜指南章节中找到更多有关视图注册的信息:

Another alternative to accomplish this scenario would be by decoupling View1 from the ContentRegion where Navigation is performed. 实现此方案的另一种方法是将View1与执行导航ContentRegion分离。 Below is a possible View Tree design which keeps View1 away from unloading and loading: 下面是一种可能的“ 视图树”设计,它可以防止View1卸载和加载:

MainShell:
* Region1
  - View1
* ContentRegion
  - ModuleShellView
  - Module2ShellView

I hope this helps. 我希望这有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM