我想强制内容页面中的数据绑定属性更新。在这种情况下是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
事件。我只想“刷新”视图的边界数据。 最佳答案
如果您的视图模型已实现INotifyPropertyChanged
-您可以尝试使用null / empty参数引发PropertyChangedEvent-这将强制更新所有绑定属性-more details here。
public void RaiseAllProperties()
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(null));
}
关于c# - 如何强制View更新Xamarin Forms中的绑定(bind)属性?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45990581/