简体   繁体   中英

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?

您可能应该对Textblock的text属性使用绑定,并实现INotifyPropertyChanged,如下所示: http : //msdn.microsoft.com/zh-cn/library/ms743695%28v=vs.110%29.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM