I have a WPF application that has a text box with binding like so:
<TextBox Grid.Row="2" x:Name="MyTextBox">
<TextBox.Text>
<Binding Path="Name"
UpdateSourceTrigger="PropertyChanged"/>
</TextBox.Text>
</TextBox>
Now, I wnt to programatically set the text. Here's the code behind:
public string Name { get; set; }
public MyUserControl() //the constructor
{
InitializeComponent();
Name = "some text";
}
When I do this, the text box is empty when i run the app. If i remove the binding:
<TextBox Grid.Row="2" x:Name="MyTextBox">
</TextBox>
I can set the text in code behind and it appears when I run the app.
MyTextBox.Text = "some text";
How do i set the text of a text box in code behind when the binding property is set? Thanks