Silverlight PRISM,显示/隐藏模块问题
我使用 PRISM 框架创建了一个项目。我有一些模块可以在 shell 中注册和显示,并且效果很好。我需要做的是当从事件聚合器接收到特定事件时动态显示和隐藏模块。
我触发了一个应该接收的 DisplayModule 事件并隐藏现有模块并显示一个新模块,但我的问题是我应该在哪里接收此事件并显示该模块?外壳?如果是这样,我将如何执行此操作,因为 shell 是顶层并且似乎没有继承所需的 Unity 方法。
我还认为我可以有一个单独的模块来侦听 DisplayModule 事件并使用区域管理器隐藏前一个模块并显示新模块。但这需要引用所有其他模块才能解析它们的类型,这是不好的做法吗?
希望这是有道理的。
谢谢您的宝贵时间
I have created a project using the PRISM framework. I have a few modules that I can register and display in the shell and this works fine. What I need to do is dynamically display and hide the modules when a particular event is received from the event aggregator.
I fire off a DisplayModule event that should be received and hide an existing module and show a new one, but my question is where is the place I should receive this event and display the module? the shell? if so, how would I do this as the shell is the top level and doesn't seem to inherit the required Unity methods.
I also thought I could have a seperate module that listened for the DisplayModule event and used the region manager to hide the previous module and show the new one. This would need to reference all other modules to be able to resolve their type though, is this bad practice?
Hope that makes sense.
Thankyou for your time
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不过,您无法卸载整个模块。您可以动态加载一个,但不能卸载一个。有关详细信息,请阅读以下文章中的按需加载模块:http://msdn.microsoft.com/en-us/library/dd458911.aspx
假设:我将从假设开始,当你说你想要要卸载模块,您实际上只想从应用程序中删除其所有视图。
首先,我们来谈谈模块如何工作以及它们如何在 shell 上显示其内容。
您的 shell 将具有一个或多个区域,您的模块可以在初始化时向其注册视图。
不过,您可以做的是更改模块初始化以跟踪已在此模块中注册的视图并在适当时卸载它们。
这样,您的 Shell 就可以发布名为
UnloadModuleRequest
的事件(类型为CompositePresentationEvent
),并让任何监听的模块卸载其已注册的任何视图。我希望这接近您想要的。
You can't unload an entire module, though. You can dynamically load one, but not unload one. For more information read Loading Modules on Demand in the following article: http://msdn.microsoft.com/en-us/library/dd458911.aspx
Assumption: I'm going to start off with the assumption that when you say you want to unload a module, you really just want all of its views to be removed from your application.
First off, let's talk about how your modules work and how they show their content on your shell.
Your shell will have one or more Regions that your modules can then register views with when they are initialized.
What you can do, though, is change your module initialization to track views that have been registered with this module and unload them when appropriate.
That way your Shell can publish an event called
UnloadModuleRequest
(of typeCompositePresentationEvent<string>
) and have any module listening unload any views it has registered.I hope this is close to what you are wanting.
以下线程处理类似的情况并解释实现目标的可能方法:
设计讨论 http://compositewpf.codeplex.com/Thread/View.aspx? ThreadId=59827
请告诉我这是否有帮助。
达米安·申克尔曼
http://blogs.southworks.net/dschenkelman
The following threads deal with similar situations and explain possible ways of achieving your goals:
design discussion http://compositewpf.codeplex.com/Thread/View.aspx?ThreadId=59827
Please let me know if this helps.
Damian Schenkelman
http://blogs.southworks.net/dschenkelman