.net - Dependency property not set in OnOk -


if edit text in textbox , press enter in order fire click event of default key, don't correct value in click handler.

how can value in handler?

here xaml:

<window x:class="wpfapplication1.defaultkeywindow"     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"     title="defaultkeywindow" height="300" width="300"> <stackpanel>     <textbox text="{binding test}" />     <button click="onok" isdefault="true">ok</button> </stackpanel> </window> 

and here code behind:

    public partial class defaultkeywindow : window {     public string test     {         { return (string)getvalue(testproperty); }         set { setvalue(testproperty, value); }     }      // using dependencyproperty backing store test.  enables animation, styling, binding, etc...     public static readonly dependencyproperty testproperty =         dependencyproperty.register("test", typeof(string), typeof(defaultkeywindow), new propertymetadata("initial value"));       public defaultkeywindow()     {         initializecomponent();         this.datacontext = this;     }      private void onok(object sender, routedeventargs e)     {         messagebox.show("value of test " + test);         dialogresult = true;     } } 

by default, textbox won't update binding until loses focus. can around setting updatesourcetrigger:

<textbox text="{binding test, updatesourcetrigger=propertychanged}" /> 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

javascript - addthis share facebook and google+ url -

ios - Show keyboard with UITextField in the input accessory view -