Inside the model there is a live list of devices, each device has its own fields. How to notify the list in the VM, so that he updated the View?

Updating the fields in this list could be done through INPC, but it seems to me that this is not the best option, since the model is cluttered and it is not possible to serialize it binary. I see that it is necessary to write an additional model to the existing ones and notify about changes in it, but then you need to adjust the logic in order to work with these classes, and not with the model itself.

Model:

[Serializable] public class Group { public string Name { get; set; } public List<Computer> PCList { get; set; } } [Serializable] public class Computer { public string Name { get; set; } public bool Status { get; set; } } 

Logics:

 public class Logic { private List<Group> _Groups; public List<Group> Groups { get { return _Groups; } set { _Groups = value; } } // code public Logic() { // code _Groups = LoadGroups(); _Server.Start(); } private void ClientConnectedEvent(object sender, MyArgs e) { Computer comp = new Computer(); // code _Groups[0].PCList.Add(comp); } } 

VM:

 public class MainWindowViewModel { public MainWindowViewModel() { Groups = new ObservableCollection<Group>(App.Logic.Groups); } public ObservableCollection<Group> Groups { get; set; } } 
  • Everything is simple - you do not need to serialize the VM, you must have separate classes for this (which are only for serialization and will be used and do not contain logic). Well and VM do high-grade - with INPC and other conveniences. - Andrey NOP
  • @AndreyNOP I understand that I didn’t go the right way, I have a View (interface), a VM (commands, interface bindings to a model, without any logic) and a Model (data itself and interaction with them). Here I have to add a 4 ModelVM element which should have all the alerts and there will be application logic in it? - i4el0vek
  • one
    No, application logic must be in VM: commands, properties for binding + logic. And the logic of storing / receiving data should be in the model, in the same place you will have serialization, since model entity classes will be without logic. If your model classes also have some kind of logic, then you need to add more model lightweight DTO classes for serialization. ru.stackoverflow.com/q/456623/218063 - Andrey NOP
  • @AndreyNOP It turns out that I will have one big, main VM containing all the logic, notifications, properties, etc., will it also branch out a smaller VM for interacting with windows? The server that is responsible for changing the list of devices (data) should be located in the model or in the VM and at certain times just update the model? - i4el0vek
  • one
    You will have a class in the model, for example, Device (or DeviceDto ), which you can normally deserialize. And in VM there will be a DeviceVM class to which the View will bind, with all the INPCs and so on. When a VM polls a model, it returns the Device list to it, and the VM based on it makes itself a list already from DeviceVM ( ObservableCollection<DeviceVM> ). Then, when you figure it out, you can connect some mapper (for example, AutoMapper) and entrust the work on converting model classes to Vm ones (well, this is optional, just to let you know that there is such an opportunity)

0