Accessing a shared Menu in Application Shell

Topics: Prism v1
Jan 27, 2009 at 3:01 PM
Hi All

Busy learning prism here and was wondering what the best way to add items to a shared Menu that exists in the Shell.

I would like each module that gets loaded to create menu items in main shared menu in my Shell view.

Any tips greatly appreciated
Jan 28, 2009 at 5:10 PM



Since the Menu and MenuItem classes inherit from the ItemsControl control, what you only need to do is define the control as a region like this:




<MenuItem Header="_File" cal:RegionManager.RegionName="GlobalCommandsRegion">

<!—Shell Menu Item -->




Then, in your modules, you can get a reference to the region through the region manager and add menu items like this:


IRegion globalCommandsRegion = regionManager.Regions["GlobalCommandsRegion"];


// Add a menu item bound to a command.

globalCommandsRegion.Add(new MyModuleMenuItem());


You could do the same with a Toolbar control and add buttons from your modules:



<ToolBar x:Name="MyToolbar" cal:RegionManager.RegionName="GlobalCommandsRegion">


<!— You need this Separator to avoid having troubles when showing controls from your modules -->

<Separator />




For a more complex manipulation on where the items should be placed and nested hierarchies, you might consider creating a MenuService for these purposes, that updates the UI in a custom way.


Please let me know if this helps.


Mariano Converti