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.
I had a problem posted and solved in this SO question. It turned out to be very much related to Mr Bugnion's answer here (which helped me tremendously, thank you!)
What I've found is you don't need to store the view-model property in ViewModelLocator at all. Just use ServiceLocator
to create an instance with a key, and in your "Dialog Service", pass the key to ShowDialog
.
Also, as mentioned in this thread already, use method Messenger.Default.Send
and remember to call viewModel.Cleanup()
afterwards to unregister the view-model from Messenger
, thereby preventing phantom view-models from trying to process future messages sent to all instances of the view-model class type.