如何将Control.Property一个属性绑定在code-背后? [英] How to bind a Control.Property to a property in the code-behind?
本文介绍了如何将Control.Property一个属性绑定在code-背后?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个文本框在我的WPF窗口。
I have a TextBox in my WPF window.
我在所谓的文字以及背后的code的属性。
I have a property in the code behind called Text as well.
我要text属性绑定到Text属性(即当该属性的值更改文本框的值也应updadated。
I want the text property to be bound to the Text property (i.e. when the value changes in the property the textbox value should also be updadated.
感谢
推荐答案
您必须设置TextBox控件的DataContext的(或任何其父母)到你的窗口:
You have to set the DataContext of the TextBox control (or of any of its parents) to your window:
myTextBox.DataContext = this;
然后在您的XAML:
then in your XAML:
<TextBox Text={Binding Text} x:Name="myTextBox"/>
这篇关于如何将Control.Property一个属性绑定在code-背后?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文