c# - Understanding WPF - store Data in Model or ViewModel -


i unsure store data in wpf application. there 2 principles might collide. please clear up?

principle 1: data should stored in model.
follows, example observablecollection<string> articles should stored in model. property in viewmodel make available view.

principle 2: states relying on view should stored in viewmodel.
means string _selectedarticle variable corresponding property string selectedarticle should stored in viewmodel.

so far, i've put methods or values don't affect view model, because (maybe too) followed principle 2. i'm not sure if right approach.

should keep data in model , in viewmodel or there place store data?

the simple answer be: data should stored belongs.

  • the model should contain data - may contain data got external services, user input, data access layer , other.
  • viewmodel should wrap part of data, wich presented user, proper wrappres provide ability view , change data - public properties, observablecollections, etc. if there many visual representations of same data in app, must build appropriate viewmodel each representation (view).
  • view consumes viewmodel, additionally can have validation (not verification) logic , associated parameters in it.

in case model should have list<string> articles. viewmodel consume list , build observablecollection<string> articles in constructor. , selectedarticle should stored in viewmodel too, if value used navigating within view , never used in model or saved db somewhere in data access layer.


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -