Binding: 'XXX' property not found on 'YYY', target property: 'Xamarin.Forms.Label.Text'

一笑奈何 提交于 2021-01-27 17:10:27

问题


I'm using Xamarin Forms using MVVM. I'm getting the following in the log:

Binding: 'XXX' property not found on 'YYY', target property: 'Xamarin.Forms.Label.Text'

Not sure is it related but when I update a variable within my Command function, this variable's updated value is not being reflected in the view. This is not happening in my other viewmodels and views. I'm not sure why.

Please help!

This is how I define the variable in the viewmodel and binding in the view.

ViewModel

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

//...

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

//...

TestContextPassing = "456";

View

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

回答1:


You need to implement INotifyPropertyChanged to your class and do as below

 OnPropertyChanged("TestContextPassing");

or

OnPropertyChanged(nameof(TestContextPassing));


来源:https://stackoverflow.com/questions/45205652/binding-xxx-property-not-found-on-yyy-target-property-xamarin-forms-labe

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!