Menu Driven Navigation

Topics: Prism v4 - Silverlight 4
Oct 28, 2010 at 6:39 PM

Are there any samples or quick starts of using Prism navigation with a Menu? Basically the Menu should be databound to data the defines it. Then I need some way to load a view into a region based on the menu item being selected?

So, in my shell I would have a menu. There would also be a MainRegion or something that is most of the screen other then title bar and menu. Selecting a menu item should load a view into MainRegion. Bonus points.... if the view is in a module that hasn't been loaded yet then what?

Off the top of my head I think I would need a view model with a ICommand like "LoadView". The menu items are bound to that command (somehow?) and the command in the ViewModel checks if the view is in a loaded module.

Is this possible? How would I know what module the view is in? Do I need that info in the menu data?

I can find samples of doing this stuff with the SL navigation framework... but not with the prism navigation/regions stuff.





Oct 29, 2010 at 8:10 PM

Hi BOb,

There is no an application like you described, but the Region Navigation Quickstart is pretty similar to this. For example you could assign a list of views to the right menu to define it. This menu is an ItemsControl, and as you mentioned that you need commands in each menu item, you could add to this buttons (it is also demonstrated in the Quickstart). Additionally, in this quickstart views are loaded based on the options selected in the right menu, as you required.

If you need to know what is the current active view, you could check the following forum thread: Recognize active view

On the other hand, take into account that the Journal of Prism Navigation could provide you the Uri of the view where you navigated to (e.g. ModuleA\View1). If you want more information about this, you could take a look at the following forum thread: How to get resulting view from RequestNavigate?

Regarding to load modules on demand and how to manage this, you could take a look at the Modularity Quickstart, since it provides guidance on this topic.

For more information you could check the following documentation section in the Prism4.chm:

  • View-Switching Navigation QuickStart
  • Modularity QuickStarts for Silverlight

 Hope this helps.

Fernando Antivero