wpf - PropertyChanged for an extended class -


my vs2015 solution consists of 2 projects: datamodel , desktopclient. datamodel has customer class - thats entityframework 6 db entity. customer has firstname property. in desktopclient there extended class customerext. in desktopclient, possible have notification customerext.firstname changes? defining partial customer across 2 projects won't work - datamodel compiled first , won't have partial properties defined in desktopclient.

public class customerext : customer, inotifypropertychanged {      public object clone()     {         return this.memberwiseclone();     }      private bool _ischecked;     public bool ischecked     {         { return _ischecked; }         set         {             this._ischecked = value;             notifypropertychanged("ischecked");         }     }      #region inotifypropertychanged      public event propertychangedeventhandler propertychanged;     private void notifypropertychanged(string info)     {         this.propertychanged?.invoke(this, new propertychangedeventargs(info));     } } 

unfortunately, if base class not implement inotifypropertychanged safest way write wrapper class , use in software. can fit in custext, or make separate if feel want layer.

this assumes while may not control customer class, control of code creating/editing customer instances, can use new class instead, convert original customer class when needed (such database transaction).

public class customerext: inotifypropertychanged {     customer _customer = new customer();      public object clone()     {         return this.memberwiseclone();     }      private bool _ischecked;     public bool ischecked     {         { return _ischecked; }         set         {             this._ischecked = value;             notifypropertychanged("ischecked");         }     }      #region wrapperproperties      public bool firstname     {         { return _customer.firstname; }         set         {             _customer.firstname= value;             notifypropertychanged("firstname");         }     }      #endregion      public customer tocustomer()     {         // returning copy of _customer instance here safer returning         // reference, otherwise properties altered directly     }       #region inotifypropertychanged      ... } 

some of gets little easier if have icustomer interface , used during database calls, can skip formality of retaining customer instance.

i remember there being third party libraries have tried automate process - have never tried them and/or didn't trust them work properly.


Comments