c# - force TextBox to refresh -
i have normal wpf textbox control bound string property. need displayed text updated after binding or .text property updated. have tried
((textbox)sender).getbindingexpression(textbox.textproperty).updatesource(); ((textbox)sender).getbindingexpression(textbox.textproperty).updatetarget();
in textchanged event handler.
i've tried updatesourcetrigger=explicit
on binding. i've tried
application.current.dispatcher.begininvoke( dispatcherpriority.input, new action(() => { statustextbox.text = "newvalue"; }));
and many different combinations of these. text displayed changes once method update textbox exits.
xaml:
<textbox x:name="txbox" height="150" margin="0,0,0,0" verticalalignment="top" textwrapping="wrap" verticalscrollbarvisibility="auto" acceptsreturn="true" verticalcontentalignment="top" text="{binding textproperty}"width="200" />
your method if it's doing alot of work holding ui thread () order of execution). whatever doing in method - in background thread.
private void somemethod() { task.factory.startnew(() => { /// logic here //update text on ui thread application.current.dispatcher.begininvoke( dispatcherpriority.input, new action(() => { statustextbox.text = "newvalue";})); //continue rest of logic take long time });
just make sure if in method touching ui elements, on ui thread, otherwise crash. another, possibly better way let ui thread know raisepropertychanged want binding know about, instead of directly manipulating ui element.
Comments
Post a Comment