How do I structure MVVM with Collections?

后端 未结 4 485
不知归路
不知归路 2021-02-01 17:45

I\'m having trouble understanding how to apply the MVVM pattern when Lists/Collections are involved.

Say the MainModel has a few properties and methods, as

4条回答
  •  面向向阳花
    2021-02-01 17:59

    Here is an answer that I think addresses this issue very nicely using an ObservableViewModelCollection

    It's nice and lazy. It takes an ObservableCollection and a ViewModelFactory in the ctor. I like it because it keeps state at the model layer where it belongs. User operations on the GUI can invoke commands at the VM which manipulate the M via public methods on the M. Any resulting changes at the M layer will be automatically handled by the class in this link.

    https://stackoverflow.com/q/2177659/456490

    Note my comment regarding SL vs. WPF

提交回复
热议问题