MVVM - child windows and data contexts

Posted by GlenH7 on Programmers See other posts from Programmers or by GlenH7
Published on 2012-09-10T21:44:51Z Indexed on 2012/09/10 21:49 UTC
Read the original article Hit count: 364

Filed under:

Should a child window have it's own data context (View-Model) or use the data context of the parent? More broadly, should each View have its own View-Model? Are there are any rules to guide making that decision? What if the various View-Models will be accessing the same Model?

I haven't been able to find any consistent guidance on my question. The MS definition of MVVM appears to be silent on child windows.

For one example, I have created a warning message notification View. It really didn't need a data context since it was passed the message to display. But if I needed to fancy it up a bit, I would have tapped the parent's data context.

I have run into another scenario that needs a child window and is more complicated than the notification box. The parent's View-Model is already getting cluttered, so I had planned on generating a dedicated VM for the child window. But I can't find any guidance on whether this is a good idea or what the potential consequences may be.

FWIW, I happen to be working in Silverlight, but I don't know that this question is strictly a Silverlight issue.

© Programmers or respective owner

Related posts about mvvm