CheGuevarasBeret
CheGuevarasBeret

Reputation: 1414

WPF Module toolbar prism

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

Upvotes: 1

Views: 856

Answers (1)

Lukazoid
Lukazoid

Reputation: 19416

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.

Upvotes: 2

Related Questions