CB4
CB4

Reputation: 748

WPF textblock does not update

I have a WPF project in that I have multiple WPF windows.

In one of the window, I called it Window2 I have a text block as follow:

<TextBlock Grid.Row="0" Name="motorTitle" Text="this is test" Visibility="Visible" Foreground="Red" Grid.Column="0" FontSize="20" HorizontalAlignment="Center"></TextBlock>

In the code behind of Window2 file, I have the following:

public string text = ".";    
    private void timer_Tick(object sender, EventArgs e)
{
    this.motorTitle.Text = text;
}

In a different WPF window I called it MainWindow I try to update the text of Window2 by doing this

   Window2.text = "my text";

So, when I run in debug mode, I can see Window2's text variable changed to "my text" but it does not update to the textblock on the display.?

I did a try & catch but nothing found.

Any idea?

Upvotes: 0

Views: 274

Answers (1)

You should probably use binding for the Textblock's text property and implement INotifyPropertyChanged, like this: http://msdn.microsoft.com/en-us/library/ms743695%28v=vs.110%29.aspx

Upvotes: 1

Related Questions