初始化后如何激活/停用模块的视图?
这与 WPF 或 Prism 的复合应用程序指南相关。
我的 shell 中有一个“MainRegion”。 我的各种模块将被加载到这个主要区域中。 我可以在菜单中填充可用模块的列表并选择它们进行加载。 单击菜单时,我这样做:
var module = moduleEnumerator.GetModule(moduleName);
moduleLoader.Initialize(new[] { module });
第一次一切正常,因为执行了模块的Initialize()方法,但是在初始化Module1、Module2和Module3之后,当我再次单击加载Module2时没有任何反应。
我的问题:在执行模块的初始化方法后,如何按需激活模块?
感谢您的帮助!
This relates to Composite Application Guidance for WPF, or Prism.
I have one "MainRegion" in my shell. My various modules will be loaded into this main region. I can populate a list of available modules in a menu and select them to load. On the click of the menu I do:
var module = moduleEnumerator.GetModule(moduleName);
moduleLoader.Initialize(new[] { module });
At the first time all works ok, because the Initialize() methods of the modules are executed, but after Module1, Module2 and Module3 are initialized, nothing happens when I click to load Module2 again.
My question: how can I activate a module on demand, after its initialize method has been executed?
Thank you for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您应该有一个属于您所在区域的 ContentControl。 然后您需要将所有模块添加到该区域。 当您单击菜单时,您应该使用该区域的 Activate(...) 方法来激活特定模块。
You should have a ContentControl that will be your region. Then you will need to add all your modules to this region. When you click on the menu you should use Activate(...) method of the region in order to activate the particular module.
这是否意味着当您激活模块时,可能与其重叠的其他模块将设置为 Visibility.Collapsed ?
Does this mean when yuou activate module, then other modules that may be overlapped by it are set to Visibility.Collapsed?
您实际上并未激活该模块。 您激活某个区域中的视图。 阅读这篇文章。
对于任何模块,Initialize 方法仅调用一次。 事实上,当您调用 LoadModule 时,您会看到模块中的视图被激活,我猜这是因为 Initilalize 方法正在向区域注册视图。 这将激活视图。 如果您有多个视图,则最后注册的视图将是活动视图。
要激活视图,您需要调用区域的 Activate 方法(假设注入了 IUnityContainer 和 IRegionManager)...
根据区域控件的类型,这将替换现有的视图或添加到其中。
You don't actually activate the module. You activate a view in a region. Take a read of this article.
The Initialize method is only called the once for any module. The fact that you are seeing a view in the module being activated when you call LoadModule I would guess is due to the fact that the Initilalize method is registering a view with a region. This will activate the view. If you had more than one view then the last registered would be the active one.
To Activate a view you need to call the Activate method of the region (assuming an injected IUnityContainer and IRegionManager)...
Depending on the type of region control this will either replace the view that is there or add to it.
您可以通过调用Regions的Remove方法来删除View。
You can remove a View by calling Regions's Remove method.