c# - 如何强制 View 更新 Xamarin Forms 中的绑定(bind)属性?

标签 c# xaml xamarin data-binding xamarin.forms

我想在内容页面中强制更新数据绑定(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/

相关文章:

c# - 以编程方式添加 Adomd 参数 C#

c# - VSCT.exe 无法加载文件或程序集

.net - 绑定(bind)到数组元素

c# - 绑定(bind)标签和文本框(XAML)时的区别

ios - "Failed to compile the generated registrar code."将 Forms 和 Visual.Material 更新到 v4.2.0.848062 后

c# - System.Net.Mail 和 MailMessage 不立即发送消息

c# - C#隐式转换面试题

xaml - Windows Phone 8 中 ListPicker 的 selectionChanged 之前的交互触发

android - Android 应用程序中 startForeground 的错误通知

c# - 使用 Xamarin MediaManager 流式传输音频