c# - INotifyPropertyChanged - Event stays null -


i trying implement following inotifypropertychanged extension:

automatically inotifypropertychanged (accepted answer) http://ingebrigtsen.info/2008/12/11/inotifypropertychanged-revisited/

but cant figure out why propertychanged eventhandler stays null. :(

i did simple wpf application test out, here xaml code:

<stackpanel orientation="vertical">     <textbox text="{binding path=seltabaccount.test, updatesourcetrigger=propertychanged}"></textbox>     <textbox text="{binding path=seltabaccount.testrelated, updatesourcetrigger=propertychanged}"></textbox> </stackpanel> 

and code behind:

public partial class mainwindow : window, inotifypropertychanged {     public event propertychangedeventhandler propertychanged;      private tabaccount _seltabaccount;      public tabaccount seltabaccount     {         { return _seltabaccount; }         set         {             _seltabaccount = value;             propertychanged.notify(() => this.seltabaccount);         }     }      public mainwindow()     {         initializecomponent();          seltabaccount = new tabaccount()         {             test = "qwer",             testrelated = ""         };     } }  public partial class tabaccount : inotifypropertychanged {     private string _test;      public string test     {         { return _test; }         set         {             _test = value;             propertychanged.notify(() => this.test);             propertychanged.notify(() => this.testrelated);         }     }      public event propertychangedeventhandler propertychanged; }  public partial class tabaccount {     private string _testrelated;      public string testrelated     {                 {             _testrelated = test + "_related";             return _testrelated;         }         set         {             _testrelated = value;             propertychanged.notify(() => this.testrelated);         }     } } 

in code behind see 1 class (its partial random testing) 2 properties should notify property change nothing happens.

the notificationextension copy , paste links provided @ top , in external cs file.

i have tried sample "normal" inotifypropertychanged implementation , works expected cant make happen extension class.

hope can me figure out. in advance.

binding work when provide datasource visual objects. if don't provide datasource , want dig properties binding not work.

under mainwindow constructor, set datacontext property of window datasource. example:

 public mainwindow()  {     initializecomponent();     // property setups      this.datacontext = this;   } 

essentially makes mainwindow properties available binding visual tree of mainwindow items.


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -