wpf - Should ViewModel respond to each ProperyChanged event or is chunking better? -


here question: in cases model collection of other model objects, may changed calculation, better not use propertychanged per model item rather have propertychanged @ parent level?

suppose have mvvm in wpf:

model:

public class model {      public ienumerable<iitemmodel> items{ get;} }  public class iitemmodel : inotifypropertychanged {      private int m_value;      public int value{          get{ return m_value; }         set{              m_value = value;              notifypropertychanged(()=>value);         }      } } 

and in viewmodel

// baseviewmodel implements inotifypropertychanged etc public class myviewmodel: baseviewmodel      {     public myviewmodel(){         var items = new model.items         items = new myobservablecolelction<itemviewmodel>(item => new itemsviewmodel(item), items);      }      public myobservablecollection<itemviewmodel> items { ; set; } } 

here, myobservablecolelction implementation of iobservablecollection has factory function passed action takes iitemmodel , creates , add itemviewmodel.

and view (xaml) binding items property not important here.

from mvvm , architecture fine. think performance, suppose iitemmodel::value calculated property, , items in model calculated, better deffer property changed per item , maybe have 1 single property changed in model class? reduce amount of firing propertychanged in cased have 1000 of them.

is make sense, , how of optimization it?

the view binding model objects in view model against separation of concern aspect mvvm can give you. view depend on model used in view model.

the amount of propertychanged causing problem rather unlikely unless have special situation. in case root cause wrong approach in solution rather property changed mechanism.

wpf/windows event driven system , can handle many events without issue. if you, try stick on pattern as possible.


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -