I have two models of the form
public class Model1 { public Int32 SomeProperty1 { get; set; } public event Action<Int32> SomeProperty1Changed; } public class Model2 { public Int32 SomeProperty1 { get; set; } public event Action<Int32> SomeProperty1Changed; public ObservableCollection<Model1> Models { get; private set; } } These models can be edited in the background stream. This data from me should receive my Control that would draw them on Canvas through code behind.
With event handling simple properties, everything is clear. I create a ViewModel that will call Dispatcher.InvokeAsync() inside the event handler for synchronization.
But how can I deal with collection event handling?
Either the ViewModel acts as a wrapper over the model object, without doing anything with it. In this case, I need to call Dispatcher.InvokeAsync() in the code behind my Control for synchronization. In this case, the least unnecessary actions come out, but for some reason I don’t like this system. I understand this is a violation of MVVM, so I do not like it.
Either the ViewModel catches collection events and does the same with its collection, but already in the window stream. I like this option more, but here comes out more unnecessary movements.