[英]How to add PRISM modules to Toolbar using MEF and MVVM
I am using PRISM 4.0 with MEF as my container. 我将PRISM 4.0和MEF用作容器。 I have defined 2 regions, ToolBar and MainRegion in my Shell.
我在Shell中定义了2个区域,即ToolBar和MainRegion。 The toolbar region is automatically populated with my ToolBarModule using a custom RegionBehaviour - AutoPopulateExportedViewsBehaviour.
使用自定义的RegionBehaviour-AutoPopulateExportedViewsBehaviour,使用我的ToolBarModule自动填充工具栏区域。 My MainRegion can contain 1 or more View modules which will be docked via a third party dock layout manager.
我的MainRegion可以包含1个或多个View模块,这些模块将通过第三方停靠布局管理器停靠。
I'm having trouble creating the toolbar buttons to represent the available views in my application. 我在创建工具栏按钮以代表应用程序中的可用视图时遇到麻烦。 My idea was to use a ToolBarService or an Event pattern so that each View module could register itself with the ToolBar in a decoupled manner.
我的想法是使用ToolBarService或Event模式,以便每个View模块都可以以分离的方式向ToolBar注册自己。
However it seems my View Module contructor is not called until I call RegionManager.RegisterViewWithRegion... 但是,直到我调用RegionManager.RegisterViewWithRegion ...,似乎没有调用我的View Module构造函数。
How can I control the initialisation of my modules so they can register with the ToolBar. 如何控制模块的初始化,以便它们可以在ToolBar中注册。 Thus allowing them to add a button but not actually show the view itself.
因此,允许他们添加按钮,但实际上不显示视图本身。 The View will only be shown when the button the view just registered is clicked.
仅当单击刚刚注册的视图的按钮时,才会显示该视图。
Thanks 谢谢
How can I control the initialisation of my modules so they can register with the ToolBar but not be shown initally?
我如何控制模块的初始化,以便它们可以在ToolBar中注册但不能初始显示?
I'm not sure what you mean by that. 我不确定你的意思。
I understand that you want modules to register it's own navigation part when they loaded. 我了解您希望模块在加载时注册其自己的导航部分。 I have similar scenario where I have menu bar on top and button bar below.
我有类似的情况,我在顶部有菜单栏,在下面有按钮栏。 Each module when loaded - inserts it's own buttons/menus using Initialize code:
每个模块在加载时-使用初始化代码插入自己的按钮/菜单:
public void Initialize()
{
this.RegionManager.RegisterViewWithRegion(RegionNames.Menu, typeof(NavigationView));
this.RegionManager.RegisterViewWithRegion(RegionNames.Toolbar, typeof(ToolbarNavigationView));
}
Those regions have actual buttons/items which when pressed call something else. 这些区域具有实际的按钮/项目,当按下按钮/项目时,它们会调用其他内容。 For examle, here is
NavigationViewModel
例如,这是
NavigationViewModel
namespace IDATT.Module.SystemManager.ViewModels
{
using System;
using System.ComponentModel.Composition;
using Microsoft.Practices.Prism.Regions;
[Export]
public class NavigationViewModel
{
[Import]
public ISecurityService SecurityService { get; set; }
[Import]
public IRegionManager RegionManager { get; set; }
public void Mail()
{
this.RegionManager.RequestNavigate(RegionNames.Tabs, new Uri(typeof(MailView).Name, UriKind.Relative));
}
public void MaintainUser()
{
this.RegionManager.RequestNavigate(RegionNames.Tabs, new Uri(typeof(MaintainUserView).Name, UriKind.Relative));
}
public void MaintainGroup()
{
this.RegionManager.RequestNavigate(RegionNames.Tabs, new Uri(typeof(MaintainGroupView).Name, UriKind.Relative));
}
public void MaintainMailTemplate()
{
this.RegionManager.RequestNavigate(RegionNames.Tabs, new Uri(typeof(MaintainMailTemplateView).Name, UriKind.Relative));
}
public void SetUpOptions()
{
this.RegionManager.RequestNavigate(RegionNames.Tabs, new Uri(typeof(SetUpSystemManagerOptionsView).Name, UriKind.Relative));
}
public void Logout()
{
this.SecurityService.Logout();
}
}
}
It looks like I can "force" the constructor of my view module to be called by using a custom RegionBehaviour. 看起来我可以通过使用自定义RegionBehaviour来“强制”视图模块的构造函数。 Inside of this I can cast my view module to a specific base view or interface type and call the a function.
在其中,我可以将视图模块转换为特定的基本视图或接口类型,然后调用a函数。 This will then register my view with the toolbar but not necessarily show the view in the "main" region of my application.
然后,这会将我的视图注册到工具栏,但不一定在应用程序的“主要”区域中显示该视图。
Thanks for your help. 谢谢你的帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.