Turning module views On/Off

Topics: Prism v2 - Silverlight 4
May 17, 2010 at 8:30 PM

It’s a common requirement to turn the views in specific modules on/off or to add more view in a specific module in response to user action. What is the best way to accomplish this? Is there any extensibility point within Prism which can be used to accomplish this? (I can write a wrapper class and make all modules register to it on initialization and perform all such operations through this wrapper class, I am interested in knowing if there is a better way to do this)

p.s. – I am using Prism v2 with Silverlight 4

May 19, 2010 at 2:40 PM


Before going into the question itself, please note that although views are inside modules, they cannot be added or removed from them. Modules are logical units in your application, and are not part of the UI. Views are the composite portions of the user interface, and they can be added into regions, which are not inside modules. You can find a more detailed explanation of this subject in this thread, where you can also find some information about loading a view in response to user action.

As for turning views on and off, you probably don’t need to use an extensibility point. A possible approach for this would be to publish events through the EventAggregator in response to user action, and have your modules listen to those events so that they show or hide views when needed (you could find Erwin Van Der Valk’s Outlook style application useful for understanding this). You can check this post by Matias Bonaventura where he explains how to hide and show views in a Prism application.

I hope you find this helpful.

Guido Leandro Maliandi