What is the best way to handle navigation with PRISM?
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 b开发者_Go百科y 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?
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.
精彩评论