c# - WPF Binding Label Content to Property -
i have read several articles , can't quite seem label update when property changed. propertychanged event firing, , property updating new text label not updating. help!
xaml
<grid.resources> <c:userinformation x:key="mytaskdata"/> </grid.resources> <label name="lbltasknametitle" content="{binding path=proptaskname, updatesourcetrigger=propertychanged}"/>
window
userinformation t = new userinformation(); t.proptaskname = "updated task name"; this.datacontext = t.proptaskname;
code behind
class userinformation : inotifypropertychanged { private string strtaskname = "task name: "; public string proptaskname { { return this.strtaskname; } set { this.strtaskname = value; notifypropertychanged("proptaskname"); //call method set off propertychanged event. } } //inotifypropertychanged stuff public event propertychangedeventhandler propertychanged; private void notifypropertychanged(string propertyname) { if (propertychanged != null) { propertychanged(this, new propertychangedeventargs(propertyname)); } }
updated reflect comment suggestions.
xaml should be:
<label name="lbltasknametitle" content="{binding path=proptaskname, updatesourcetrigger=propertychanged}"/> userinformation t = new userinformation(); t.proptaskname = "updated task name"; this.datacontext = t;
Comments
Post a Comment