views:

364

answers:

2

I'm writing a Silverlight app using the MVVM pattern. I have a main view (UserList.xaml) and corresponding vm (UserListViewModel.cs). This is used to list a collection of users. I also have a UserControl (User.xaml - invoked as a modal dialog) that is used to add details for a new user. This also has a viewmodel of it's own (UserViewModel.cs).

My questions is how do you pass information (a user object) from the child viewmodel back up to the parent once the child view is dismissed? I need to update the collection in the parent viewmodel when I do a save on the child viewmodel. Should be simple enough but the parent viewmodel has no idea when the child is dismissed. Even if the UserViewModel.User property is changed and it's PropertyChanged event is raised, UserListViewModel is not aware of it.

Any help here is greatly appreciated. I've read everything about mvvm in Silverlight that I can find but there are still some gaps. I hope I've outlined my issue clearly.

+2  A: 

Hi arch

There are many ways of doing this. You could pass an instance of the parent VM to the child VM in the constructor. You could have the parent VM subscribe to an event that the child VM exposes when your code has run.

Hope this helps. :)

Ray Booysen
A: 

Hi Ray,

Thank you - this is a case of over-analysis. I was trying so much to think of this problem in an MVVM mindset that I just disregarded the idea of creating an event that the parent VM listens to.

I appreciate it the grounding.

Regards, AV

arch