Adding Same View to Different Regions

Topics: Prism v2 - Silverlight 3
Jul 30, 2009 at 3:22 AM

Hi All,

I have a Chart View with a View Model attached to it. The view model has nothing but a collection of Date Time & Value pair. Now what i want to do is use this same view to show two charts one showing Total Visitors and other showing Total Page Hits.

Now my question : Is it possible in PRISM to have the same view registered at two places and having independent view models at run time. How do i achieve this. I need to inform the Vew model which data source to connect. Say when the view is for Total Visitors it should initialize the View Model from Visitors source table and when the view is for Total Page Hits the view model should be initialized with the Page Source table.

I am not able to figure out how to add the same view to different region and have the same view model populated with different data?

Thanks & Regards,

Yusuf Nazami

Jul 30, 2009 at 5:24 PM

Hi Yusuf,

 Yes, this is possible in Prism, but you have to create two different instances of the same view. As the views will be created and added by the same module to both regions an approach similar to this can be taken (this is simplified just to show this situation):

//Initialize method of the module 

public void Initialize()


ChartViewModel totalVisitorsModel = container.Resolve<ChartViewModel>();




ChartViewModel totalPageHitsModel = container.Resolve<ChartViewModel>();




You have two different view models (two different views), each with their own DataSource which is the goal.

Please let me know if this helps.

Damian Schenkelman