c# - WPF - Databinding Issue -


i have bound control property on page. property binding returns class. binding works if set property new instance of class ui not updated.

could point in right direction solve issue, have tried implementing inotifypropertychanged doesn't work.

the code follows..

xaml - basic trying bind label property @ minute.

<grid>         <label content="{binding studentname}"></label>         <button width="100" height="75" click="button_click" ></button> </grid> 

c#

this.datacontext = parentwindow.selectedstudent; 

the parent window c# note parent window implements inotifypropertychanged

public event propertychangedeventhandler propertychanged;  public ucstudent selectedstudent {                         {                 if (_selectedstudent == null)                 {                     _selectedstudent = new ucstudent();                 }                  return _selectedstudent;             }              set             {                 if (_selectedstudent != value)                 {                     _selectedstudent = value;                     onpropertychanged("selectedstudent");                 }             }  }   protected void onpropertychanged(string name)     {         propertychangedeventhandler handler = propertychanged;         if (handler != null)         {             handler(this, new propertychangedeventargs(name));         }     } 

the issue when set selectedstudent property new selected student binding not update.

while approach uses generics , expression, can type property changes, concept same. use expression, use string. you'll want return if propertychanged null. otherwise, fire event without declaring new event handler first.

public event propertychangedeventhandler propertychanged;      protected void notifypropertychanged<t>(expression<func<t>> expression)     {         if (this.propertychanged == null) { return; }          string propertyname = getpropertyname(expression);          propertychanged(this, new propertychangedeventargs(propertyname));     } 

this approach allows view model type notification.

this.notifypropertychanged(() => this.selectedapplication); 

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -