我正在使用 Prism 的 CAG 开发 WPF 应用程序。 我想要实现的是创建模块(ModuleA)的新实例并将它们加载到 TabControl 中。
我可以使用 moduleInfo 对象实例化模块,并通过 Assembly 加载它们并调用 CreateModule(type) 方法。
我实际上可以在 UI 中看到不同的模块,但问题是当我开始与不同的模块交互时(例如在作用域区域中加载或卸载视图),所有活动似乎只发生在最后加载的模块上。
例如,我有 2 个 ModuleA“实例”作为 2 个 TabItem,它们都有用于 Load() 新视图的命令按钮。 当我选择第一个模块(通过选择第一个 TabItem)并单击按钮加载视图时,视图将加载到第二个模块中。
有人知道如何解决这个问题吗? 让我相信,即使我在 UI 上“看到”两个单独的模块,实际上只有一个实例或者 CreateModule 创建克隆?
任何人 ? 感谢所有帮助!
I am developing a WPF application using the CAG from Prism. What I want to achieve is create new instances of a module (ModuleA) and load them in a TabControl.
I am able to instantiate the modules using the moduleInfo object and loading them through the Assembly and calling the CreateModule(type) method.
I can actually see the different modules in the UI, but the problem is when I start interacting with the different modules (for e.g. loading or unloading views in scoped regions) all the activity seems to happen only on the last loaded modules.
So for e.g. I have 2 'instances' of ModuleA as 2 TabItems and they both have command buttons to Load() new views. When I select the first Module (by selecting the first TabItem) and click the button to laod the view, the view gets loaded in the second module.
Anyone know how to sort this problem? Makes me believe, even if I 'see' two seperate modules on the UI, there is actually only one instance or the CreateModule creates clones ?
Anyone ? all help appreciated !
发布评论
评论(1)
正如 Erik 所解释的,加载模块和视图在 Prism 中是非常不同的概念。
在理解这一点并处理与问题中类似的场景时,以下线程非常有用:
我希望这有用。
谢谢,
达米安
As Erik explained, loading Modules and Views are very different concepts in Prism.
The following threads are useful when understanding this and deal with a scenario similar to the one from the question:
I hope this is useful.
Thanks,
Damian