Adding to shell menus from modules

Topics: Prism v4 - Silverlight 4, Prism v4 - WPF 4
Mar 1, 2011 at 10:00 AM

I am currently in the process of putting together a prototype Prism application to illustrate the design patterns that we will be using here and so I am trying to get everything "right".

Loading views into regions seems quite neat (using MEF) and with custom adapters I am able to use various DevExpress controls (such as the docking control) for layout. All good so far.

My problem is how best to extend menus from modules. Ideally I want to use the DevExpress BarManager, but I guess my question would would also work for the .NET framework Menu/MenuItems too.

Using regions don't seem to be the right choice here. This would require a custom adapter and I suppose a xaml file for each menu item linked to a Command most likely stored somewhere in the main module controller. This seems like a messy pattern (if I can even get this to work - I'm not sure exactly what I would be putting in the xaml file for DXBarManager which has a lightly more complex structure than menu/menuitem).

My next thought (and the way I will head unless a decent suggestion presents itself) was to have a "MenuService" class shared from the shell that the modules can resolve and use to extend the menu. i.e. In the main module controller class for each module you would resolve the MenuService and call various methods (e.g. MenuService.GetMenu("View").AddMenuItem("Properties", OpenPropertyWindowCommand) - where OpenPropertyWindowCommand is defined in the controller class and resolves a particular view and loads it into a region in the shell.
The menu service would abstract away from the particular implementation of the menu in the shell which could follow an mvvm pattern (with the model being presented to the shell view by the service). 
I guess that this idea is something like this , which is something similar to the Extension Sites idea that was in CAB.

I have looked at the various Prism Quickstarts but can't see anything suitable in there. The closest thing is the View-Switching one but this one only really seems to suit a situation where your Links really are like Views (i.e. each "link" is really arbitrary xaml), rather than an extending an actual Menu object.

What are peoples experience with this? Does anyone have any good suggestions for me?

Mar 1, 2011 at 2:57 PM


From my understanding, your approach seems a valid way to achieve the requirement you're explaining.

The first approach you've mentioned seems to be too much of an overhead since, like you've mentioned, it's not that your menu items will be an arbitrary xaml, whereas the second one seems to address the situation appropriately.

I hope you find this helpful.

Guido Leandro Maliandi

Mar 25, 2011 at 3:47 PM

The guys at DevExpress came up with quite an elegant solution to my problem using the "Merge"/"UnMerge" feature of their BarManager.

Basically, you can define a barmanager and a bar in a view and when the view is loaded the shell will merge one of the bars defined in the view into the shells main bar manager (and unmerge when the view is removed).

For module menus items (i.e. Menu links that activiate the views themselves, rather than menus for controlling the individual views), I intend to adapt this pattern with the AutoPopulateExportedViewsBehavior functionality (i.e each module will have one xaml file that defines menu items that I want added to the shell at startup).

Anyway, here is the discussion on DevExpress along with a sample project.

Note: I have since changed the way that the sample project uses their docking control following this discussion:

Mar 28, 2011 at 3:41 PM


Thank you for sharing your approach with the rest of the community, as other users with similar requirements might benefit from knowing this.

Guido Leandro Maliandi