c# - Avoid NotifyPropertyChanged in second collection -


i have 1 observable collection of class baseclass(observablecollection1<baseclass>) implements inotifypropertychanged , properties raise event when changes. want store default values on call database in observable collection(observablecollection2<baseclass>). view bound obervablecollection1 , not 2 if changes in baseclass, values updated in both 1 , 2 because of inotifypropertychanged on baseclass, how can avoid second observablecollection2<baseclass> being updated new values?

deep copy key, have make baseclass implements icloneable interface add logic needed copy object. can deep copy objects using binary serialization.

so first of all, class must marked [serializable] in order work.

[serializable]     public class baseclass: icloneable     {         /*         base class mumbers ...         */          public object clone()         {             var bf = new binaryformatter();             using (stream str = new memorystream())             {                 bf.serialize(str, this);                 str.seek(0, seekorigin.begin);                 return bf.deserialize(str);             }         }     } 

and finaly copy source collection

var copiedcollection = new observablecollection<baseclass>(sourcecollection.select(a => (baseclass)a.clone())); 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -