ViewModels communication

Topics: Bootstrappers & IoC, Getting Started
May 7, 2012 at 3:31 PM

I'm new to CM and have some questions for the follwoing scenario:

In WP7, I have a UserControlViewModel and a PageViewModel.

The page contains the usercontrol (just assume a very simple UI scenario)

The usercontrol is just a ListBox with a header and the ListBox's Items property is bound to the UserControlViewModel's Items property.

1. Of which type should the two ViewModels be in the simplest case, ie. derived from Conductor<XY>, Screen   ?

2.  How should the UserControlVM and the PageVM communicate with each other ? For example,  the UserControlVM needs the PageVM as source for its  Items property:

=> either the UserControlVM gets an instance of the PageVM to call a method "GetAllItems()" or the PageVM gets an instance of UserControlVM to call a method "SetItems()" ?

Also a general question: should the "child" VMs know their "parents" or the other way round ?

May 8, 2012 at 10:11 AM

I use the EventAggregator for these kind of scenarios, if your IoC supports Child containers you can have one EventAggregator per window, this way events will stay within a window