How can MVVM models communicate with each other ?? I read that with the case with the view-model you need to install the MVVM Light Toolkit and use Messanger. With the models in the same way ??

  • 2
    Give an example, it is not clear what you mean. Usually the model is passive. And certainly it should not depend on the UI. Ideally, a model is a separate library, for example, which can be connected either to a desktop application, or to a console application or, in general, to a web application. It would be strange if she pulls a piece of the GUI framework behind herself - Andrey NOP

1 answer 1

Models do not need to exchange data themselves. They only store data or process (convert) their data. Exchange is engaged in either a view model or business logic classes. The exchange can occur explicitly or if they implement the INotifyPropertyChanged or INotifyCollectionChanged .

  • So I do not understand the essence of MVVM. Suppose I want to file an application for this pattern, which would follow another window. I get the coordinates of another window using WinAPI, the coordinates of another window should be checked for, say, every 0.1 s. Of course, the coordinate check must take place in another thread. QUESTION! Where should the method of checking coordinates of another window be located ?? in the model, VM or even in another class ?? How should this method transfer the coordinates of another window to the property of our model, which passes them to the VM, and that in turn view, through binding ???? - One Two
  • As Andrei Akinshin would say - "Depends" =) - Anton Gorbunov
  • It seems to me that the tracking logic should be implemented in a separate class. Create an instance or get it through the view-model constructor. The view model should somehow receive data from it - it can be an Event or ReactivePrperty or a timer poll. When retrieving data, you add them to the appropriate Property view-models, for which View is bounded. Here the only question is, how much would it be in such a way to bind the window position - there was never a need to do this on WPF. You may have to do this through CodeBehind. - Anton Gorbunov
  • Already happened, without codebehind. Thank you very much. - One Two