开发者

How to bind a Control.Property to a property in the code-behind?

开发者 https://www.devze.com 2022-12-11 05:31 出处:网络
I have a TextBox in my WPF window. I have a property in the code behind called Text as well. I want the text property to be bound to the Text property (i.e. when the value changes in the prop开发者_

I have a TextBox in my WPF window.

I have a property in the code behind called Text as well.

I want the text property to be bound to the Text property (i.e. when the value changes in the prop开发者_如何学JAVAerty the textbox value should also be updadated.

Thanks


You have to set the DataContext of the TextBox control (or of any of its parents) to your window:

myTextBox.DataContext = this;

then in your XAML:

<TextBox Text={Binding Text} x:Name="myTextBox"/>
0

精彩评论

暂无评论...
验证码 换一张
取 消