Big smart ViewModels, dumb Views, and any model, the best MVVM approach?

前端 未结 2 1391
北海茫月
北海茫月 2020-12-04 16:55

The following code is a refactoring of my previous MVVM approach (Fat Models, skinny ViewModels and dumb Views, the best MVVM approach?) in which I moved the logic a

2条回答
  •  猫巷女王i
    2020-12-04 17:58

    My personal opinion is that while Model should be used to load and store data, ViewModel's responsibility is to know when this data is needed, thus using timer in a ViewModel makes sense. This way you can use your Model with different ViewModel (for which it may be sufficient to retrieve data only once, not every second).

    Few things to consider:

    • Implement your model to support Asynchronous data retrieval (very important if you want to target Silverlight)
    • Be careful about updating collection from background thread (not a problem in your example, but if you ever need to use ObservableCollection than remember that it cannot be updated from non UI thread, read more here )

提交回复
热议问题