WPF Module toolbar prism

喜你入骨 提交于 2019-12-13 03:11:30

问题


Can anyone provide a hint on how I would populate a navigation toolbar similar to the StaffLynx Entity toolbar that the Billy Hollis video displays across bottom of the app?

I only want to show a "Client" icon in the toolbar if indeed the application version running has the Client module loaded and available but am unsure how to perform this MVVM style?

Thanks


回答1:


What you want is your toolbar to have a region:

<controls:MyToolbar Prism:RegionManager.RegionName="ToolbarRegion" />

Then ensure there is a valid RegionAdapter for the type of your toolbar; You can override ConfigureRegionAdapterMappings in your bootstrapper to register additional region adapters:

protected override RegionAdapterMappings ConfigureRegionAdapterMappings()
{
    var mappings = base.ConfigureRegionAdapterMappings();

    var toolbarAdapter = Container.Resolve<MyToolbarRegionAdapter>();
    mappings.RegisterMapping(typeof (MyToolbar), toolbarAdapter);
}

Then in your modules, you can register views to display in this region, e.g:

public class ModuleA : IModule
{
    private readonly IRegionManager _regionManager;

    public ModuleA(IRegionManager regionManager)
    {
        _regionManager = regionManager;
    }

    public void Initialize()
    {
        _regionManager.RegisterViewWithRegion("ToolbarRegion", typeof(MyToolbarItem));
    }
}

Where MyToolbarItem is the view you want to be displayed in the toolbar.

Prism will then automatically instantiate an instance of MyToolbarItem and add it to the region called ToolbarRegion.



来源:https://stackoverflow.com/questions/13808342/wpf-module-toolbar-prism

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!