data binding - databinding in WPF using a base class for field creation in various forms -


i had application working fields being created in class each field generated separately in usual fashion

public class requestprofileobject : inotifypropertychanged {      public event propertychangedeventhandler propertychanged;       private string strpassword;      public string pwd      {           { return strpassword; }          set           {               strpassword = value;               // call onpropertychanged whenever property updated               onpropertychanged("pwd");           }       }       //plus other code load data field , onpropertychanged      //method  } 

then saw needed able keep track of changes , came mechanism , other features needed. needless lot of repeated code caused me have bright idea of making class these object.

public class etlbasefield  : inotifypropertychanged {     public event propertychangedeventhandler propertychanged;     private string strfieldprime;     private string strfield;     private string strfieldname;      public etlbasefield() { }      public etlbasefield(string strinputfield)     {         strfieldname = strinputfield;     }      public string field     {         { return strfield; }         set         {             if (strfield != value)             {                 strfield = value;                 // call onpropertychanged whenever property updated                 onpropertychanged(strfieldname);             }         }     }      public void load(string strvalue)     {         strfieldprime = strvalue;         strfield = strfieldprime;     }      public void empty()     {         load("");     }      public bool isdirty()     {         return strfieldprime != field;     }      protected void onpropertychanged(string propertyname)     {         if (this.propertychanged != null)         {             this.propertychanged(this, new propertychangedeventargs(propertyname));         }     } } 

this class used main class

public class requestprofileobject : inotifypropertychanged {      public event propertychangedeventhandler propertychanged;       public etlbasefield requestname = new etlbasefield("requestname");      public etlbasefield interfacename = new etlbasefield("interfacename");      //plus code loads etlbasefield things , onpropertychanged method } 

my xaml code working, bindings fields hunky dory. new invention can't figure out how bind requestname.field property xaml textbox. following

<textbox height="23" name="txtbxinterfacename" width="250"   text="{binding path=interfacename.field}" /> 

doesn't work. smart own in creating etlbasefield class? should remove inpc requestprofileobject?

use mode=twoway

<textbox height="23" name="txtbxinterfacename" width="250"       text="{binding path=interfacename.field, mode=twoway}" /> 

databinding should work etlbasefield implementing inotifypropertychanged. in case doesn't work try setting textbox's datacontext explicitly

<textbox datacontext="{binding interfacename}" height="23" name="txtbxinterfacename" width="250"   text="{binding field}" /> 

you raising onpropertychanged incorrectly!

not this

onpropertychanged(strfieldname); 

instead this

onpropertychanged("field"); 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -