如何强制 View 更新 Xamarin Forms 中的绑定属性?

Dan*_*tos 2 c# data-binding xaml xamarin xamarin.forms

我想在内容页面中强制更新数据绑定属性。在这种情况下是ContentPage Title参数。

<ContentPage x:Class="Containers.Views.ContainerPage" 
         xmlns="http://xamarin.com/schemas/2014/forms" 
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         Title="{Binding SomeStringProperty}"
         Appearing="ContentPage_Appearing">
Run Code Online (Sandbox Code Playgroud)

我得到的最接近的是这个,但它不起作用。

    private void ContentPage_Appearing(object sender, EventArgs e)
    {
        this.BindingContext = null;
        this.BindingContext = myClassInstance;
    }
Run Code Online (Sandbox Code Playgroud)

我不想实施onPropertyChange事件。我只想“刷新”视图的有界数据。

Sha*_*raj 6

如果您的视图模型已经实现INotifyPropertyChanged- 您可以尝试使用 null/empty 参数提升 PropertyChangedEvent - 这应该强制更新所有绑定属性 -此处有更多详细信息

public void RaiseAllProperties()
{
    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(null));
}
Run Code Online (Sandbox Code Playgroud)