我想在内容页面中强制更新数据绑定(bind)属性。在这种情况下是 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">
我得到的最接近的是这个,但它不起作用。
private void ContentPage_Appearing(object sender, EventArgs e)
{
this.BindingContext = null;
this.BindingContext = myClassInstance;
}
我不想实现 onPropertyChange
事件。我只想“刷新” View 的有界数据。
最佳答案
如果您的 View 模型已经实现了 INotifyPropertyChanged
- 您可以尝试使用空/空参数引发 PropertyChangedEvent - 这应该强制更新所有绑定(bind)属性 - more details here .
public void RaiseAllProperties()
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(null));
}
关于c# - 如何强制 View 更新 Xamarin Forms 中的绑定(bind)属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45990581/