.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
Post a Comment