HI,
I’m using MVVMLight and i would like a particular VM to reference to another VM’s property. Currently, i using the ViewModelLocator.SomeViewModelStatic to do it. At times, i would also like to use the methods of another viewmodel. And also using the ViewModelLocator.SomeViewModelStatic to use other ViewModels’ methods.
Is this the correct way of communicating between ViewModels?
In such case I would start by adding Inversion of Control container to the application (Autofac, Ninject or even MEF (if you’re familiar with it)) and registering within all ViewModels (you can do it manually or same IoC containers can look for specific classes in the assemblies) and Services. Then I would implement
ViewModelLocatorto work with the IoC in such a way that ViewModels would be created by it (then every dependency would be resolved by Dependency Injection and all you have to worry about is to register everything in IoC)By using IoC you can also use factory methods, that can create instances for you in ViewModels.