c# - How to get edited values in ObservableCollectionin WPF(MVVM) -


 public class pricinggrpmodel  {     public string name { get; set; }     public string description { get; set; }       }   private observablecollection<pricinggrpmodel> _mycollection;      public observablecollection<pricinggrpmodel> mycollection  {   { return _mycollection; }   set { _mycollection= value; onpropertychanged("mycollection"); }  }  mycollection.collectionchanged += new notifycollectionchangedeventhandler(mycollection_collectionchanged);     void mycollection_collectionchanged(object sender, notifycollectionchangedeventargs e) {     try     {         switch (e.action)         {                              case notifycollectionchangedaction.add:                                        break;              case notifycollectionchangedaction.remove:                 break;         }     }     catch(exception exception)     {                   } }   

i have bound 'mycollection' observablecollection datagrid's itemssource. collection change event fired while adding or removing row. couldn't track changes of existing row value. how can notification when item's property in observablecollection has been changed?

you can use newitems , olditems properties of notifycollectionchangedeventargs.

when call observablecollection.remove(), removed items present in olditems property:

void mycollection_collectionchanged(object sender, notifycollectionchangedeventargs e) {     if (e.olditems != null)     {          foreach (var removeditem in e.olditems)          {          }     } } 

the problem is, when call observablecollection.clear() method, olditems property null.

if want access cleared items, have create custom class inheriting observablecollection , override removeitem protected method. removeitem method invoked when call observablecollection.clear() can use extendedobservablecollection answer: trigger inotifypropertychanged/collectionchanged on observablecollection


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -