how to create and track multiple pairs "View-ViewModel"?

Posted by Gianluca Colucci on Stack Overflow See other posts from Stack Overflow or by Gianluca Colucci
Published on 2010-05-13T21:39:36Z Indexed on 2010/05/13 21:44 UTC
Read the original article Hit count: 503

Filed under:

Hi!

I am building an application that is based on MVVM-Light. I am in the need of creating multiple instances of the same View, and each one should bind to its own ViewModel.

The default ViewModelLocator implements ViewModels as singletons, therefore different instances of the same View will bind to the same ViewModel.

I could create the ViewModel in the VMLocator as a non-static object (as simple as returning new VM()...), but that would only partially help me. In fact, I still need to keep track of the opened windows. Nevertheless, each window might open several other windows (of a different kind, though). In this situation I might need to execute some operation on the parent View and all its children. For example before closing the View P, I might want to close all its children (view C1, view C2, etc.).

Hence, is there any simple and easy way to achieve this? Or is there any best practice you would advice me to follow?

Thanks in advance for your precious help.

Cheers,

Gianluca.

© Stack Overflow or respective owner

Related posts about mvvm-light