绑定:'YYY'上找不到'XXX'属性,目标属性:'Xamarin.Forms.Label.Text'

时间:2017-07-20 05:09:29

标签: c# xamarin.forms

我正在使用MVVM使用Xamarin Forms。我在日志中得到以下内容:

绑定:'YYY'找不到'XXX'属性,目标属性:'Xamarin.Forms.Label.Text'

不确定是否相关但是当我在Command函数中更新变量时,此变量的更新值未反映在视图中。 我的其他视图模型和视图中没有发生这种情况。我不确定为什么。

请帮忙!

这就是我在viewmodel中定义变量和在视图中绑定的方法。

视图模型

public string _testContextPassing;
public string TestContextPassing
{
    get { return _testContextPassing; }
    set
    {
        testContextPassing = value;
        OnPropertyChanged();
    }

//...

public override async Task Init()
{
    TestContextPassing = "123";
}

//...

TestContextPassing = "456";

查看

<Label Grid.Row="2" BindingContext="{Binding Source={x:Reference PhotoCapturePage}, Path=BindingContext}" Text="{Binding TestContextPassing}"/>
<Label Grid.Row="3" Text="{Binding TestContextPassing}"/>

1 个答案:

答案 0 :(得分:1)

您需要对您的班级实施INotifyPropertyChanged,并执行以下操作

 OnPropertyChanged("TestContextPassing");

OnPropertyChanged(nameof(TestContextPassing));
相关问题