Binding a Textbox to a property in WPF -
i have textbox in user control i'm trying update main application when set textbox.text property doesnt display new value (even though textbos.text contains correct data). trying bind text box property around dont know how, here code -
mainwindow.xaml.cs
outputpanel.text = outputtext;
outputpanel.xaml
<textbox x:name="textbox" acceptsreturn="true" scrollviewer.verticalscrollbarvisibility="visible" text="{binding <!--?????--> }"/> <!-- want bind text propert in outputpanel.xmal.cs -->
outputpanel.xaml.cs
namespace controls { public partial class outputpanel : usercontrol { private string text; public textbox textbox { {return textbox;} } public string text { { return text; } set { text = value; } } public outputpanel() { initializecomponent(); text = "test"; textbox.text = text; } }
}
you have set datacontext in parent of textbox, example:
<usercontrol name="panel" datacontext="{binding elementname=panel}">...
then binding be:
text="{binding text}"
and shouldn't need - referring specific elements code behind bad practice:
public textbox textbox { {return textbox;} }
Comments
Post a Comment