Silverlight PropertyChanged event not firing in two-way textbox binding -
if class property two-way bound text property of textbox, when change text in text box, "propertychanged" event of class supposed fire? doesn't in case - message box never pops when change text box content. binding works though, if properties change textbox changes, , vice versa.
edit: realize fires, when textbox loses focus. guess there must reason behind behavior.
code:
public class baselineareas : inotifypropertychanged { public event propertychangedeventhandler propertychanged; private double _impervious = 0; public double impervious { { return _impervious; } set { if (value != this._impervious) { _impervious = value; notifypropertychanged("impervious"); } } } private double _pervious = 0; public double pervious { { return _pervious; } set { if (value != this._pervious) { _pervious = value; notifypropertychanged("pervious"); } } } public void notifypropertychanged(string propertyname) { if (propertychanged != null) { propertychanged(this, new propertychangedeventargs(propertyname)); } } } private baselineareas baselineareas = new baselineareas(); public mainpage() { initializecomponent(); baselineareas.impervious = 100; baselineareas.pervious = 500; textboxtotalimperviousarea.datacontext = baselineareas; textboxtotalperviousarea.datacontext = baselineareas; baselineareas.propertychanged += new propertychangedeventhandler(baselineareas_propertychanged); } void baselineareas_propertychanged(object sender, propertychangedeventargs e) { messagebox.show(baselineareas.impervious.tostring()); }
xaml:
<textbox height="23" horizontalalignment="left" margin="138,16,0,0" name="textboxtotalimperviousarea" verticalalignment="top" width="62" text="{binding impervious, mode=twoway}"/> <textbox height="23" horizontalalignment="right" margin="0,45,226,0" name="textboxtotalperviousarea" verticalalignment="top" width="62" text="{binding pervious, mode=twoway}"/>
it's possible give textbox behavior in xaml make update on every character change:
Comments
Post a Comment