在事件上更新 Xamarin ContentPage 内容不起作用

Update Xamarin ContentPage content on event isn't working

这可能是一个基本问题,但是如何强制页面更新其内容(在它已经加载之后)?我正在尝试在网络请求后动态更新页面。事件触发,但似乎没有刷新内容。

public StartPage : ContentPage
{
    public StartPage()
    {
        var layout = new StackLayout
        {
            Children = 
            {
                new Label { Text = "Preview Page" }
            }
        };

        this.Content = layout;
    }

    //this gets called from a web service call with the text to display
    public void Update(string text)
    {
        var layout = new StackLayout
        {
            Children = 
            {
                new Label { Text = text }
            }
        };

        this.Content = layout;

        //this fires, but nothing changes
        //how can I force the page to refresh??
    }
}

如果有错误,请为代码道歉,凭记忆完成(我面前没有确切的代码)

你应该像下面这样把它放在Device.BeginInvokeOnMainThread()里面

public void Update(string text)
{
  Device.BeginInvokeOnMainThread(() =>
  {
    var layout = new StackLayout
    {
        Children = 
        {
            new Label { Text = text }
        }
    };

    this.Content = layout;
  });
}