views:

90

answers:

1

Using Prism - what is the best way to handle navigation in a WPF application? And how do you apply this? Are there any best practices?

In my application I'm currently using Event Aggregation. Any menu item or other item that should result in navigation in the program will publish an event, and the module responsible for opening the view represented by the published event will do so. This works just fine, but I have a feeling this is not the best way to handle navigation with Prism. Is it?

+1  A: 

It's as good a method as any other, at least where Prism is concerned. One way I've done it before is to set up one Module/Class as your "Navigation broker"; for MDI type applications, I usually call it WindowManager due to lack of creativity. This guy will get injected with the IRegionManager and the IEventAggregator and start listening for any "New Window" or "Navigate To" type of events and alter/create regions appropriately. If you want to get slightly clever, you can start using scoped RegionManagers:

http://msdn.microsoft.com/en-us/library/cc707903.aspx

http://blogs.msdn.com/erwinvandervalk/archive/2009/04/29/how-to-build-an-outlook-style-application-with-prism-v2-part-2.aspx

The main problem with this tactic (and using the event aggregation aspects in general) is that any CompositePresentationEvents you need to handle by multiple modules or at least "outside" of the raising module, you need to have declared in a common location (I usually put them in a project called Infrastructure). This I am not overly fond of.

JerKimball
Thanks for your answer! Navigation Broker idea sounds reasonable. I kinda do the same - just that i have one broker per module. Will have a look at the scoped Region Managers.
stiank81