2
votes

I am currently building an application using PRISM and the Microsoft WPF Ribbon control. I have so far been able to add tabs to the ribbon using RegionManager by coding the shell XAML as follows...

...
<r:Ribbon Grid.Row="0" prism:RegionManager.RegionName="{x:Static c:ShellRegion.Ribbon}">
</r:Ribbon>
...

and then adding additional tabs to the ribbon during the IModule.Initialize method of each module as follows...

<r:RibbonTab x:Class="Views.RibbonView" Header="TabX">
    <r:RibbonGroup Header="GroupX">
        <r:RibbonButton Label="Button1" />
        <r:RibbonButton Label="Button2" />
    </r:RibbonGroup>
</r:RibbonTab>

public void Initialize() {
    this.regionManager.RegisterViewWithRegion(ShellRegion.Ribbon, typeof(Views.RibbonView));
}

What I am now trying to do is to implement something similar for the RibbonApplicationMenu. I have tried the following...

<r:RibbonApplicationMenu x:Class="Views.ApplicationMenu">
    <r:RibbonApplicationMenuItem Header="MenuItem1" />
    <r:RibbonApplicationMenuItem Header="MenuItem2" />
</r:RibbonApplicationMenu>

public void Initialize() {
    this.regionManager.RegisterViewWithRegion(ShellRegion.ApplicationMenu, typeof(Views.ApplicationMenu));
}

but this actually ends up with an application menu embedded within the application menu (think click on drop down, and another drop down becomes available for you to click on also).

Obviously I can see the obvious difference between the two; for the tabs I am adding an individual RibbonTab and for the menu items I am actually adding another RibbonApplicationMenu. Thing is, I cannot find any documentation on creating what I believe are called "RegionAdapters" that I can use to "merge stuff together"; I understand why adding individual RibbonTab's works (though in the future modules may need to add multiple RibbonTab's and I would prefer not to necessarily have to code each RibbonTab individually as I currently have and as per the example above). Similarly, I understand that I am adding the incorrect child to the RibbonApplicationMenu and this is why I am resulting in an embedded RibbonApplicationMenu whereas if I coded each RibbonApplicationMenuItem individually (as I have the RibbonTab's) and add them accordingly then they too will work.

I guess the question here (yes, I have finally gotten to it) is how best to approach this?

In an ideal world, I would like to be able to have a single XAML file (per module) that contains all of the RibbonTab's that I want adding to the shell. Similarly, I would like a single XAML file per module that contains all items that I want to add to the RibbonApplicationMenu. Finally, I would like to be able to add these using the RegionManager as I currently do.

Thanks in advance for any help.

2

2 Answers

2
votes

The best way to achieve what you are trying to do is, as you said, creating a custom RegionAdapter.

This is explained in this section of the Prism documentation (under Region Adapters).

Some time ago I created a Region Adapter for the Accordion Control, which you might also find useful.

I hope this helps.

1
votes

You can find code for a RbbonRegionAdapter here. It worked for me.