Should code that displays view be coded in the View or in the ViewModel?

Topics: Prism v2 - Silverlight 3
Mar 3, 2010 at 5:49 PM

I'm new to Prism, Silverlight, and the MVVM pattern.  I'm hoping somone can chime in here and help me out.  I have read many articles over the past few months on the MVVM pattern and many are contradictory.  The application that I am buidling is in Silverlight and uses Prism for it's modular approach to buidling composite applications.  My view has a button on it and when the user clicks the button it publishes an event that essentially tells the subscriber (a view in another module) to display itself in a region.  I know I can use commanding so that the buttons click event is handled in the ViewModel via binding, but is this the right place for that kind of code?  Do you think this specific (displaying of Views) event publishing and subscribing code should be coded in the Views or in the ViewModels?

Thanks in advance for your feedback.


Mar 4, 2010 at 10:54 AM


Usually i do some kind of Controller class for the particular module, which subscribes to the events / commands. And all the add / remove views to the regions are made inside of this Controller class.

Take a look to the StockTrader project in Prism downloads, there are some examples.