简体   繁体   中英

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

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}"/>

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

 OnPropertyChanged("TestContextPassing");

or

OnPropertyChanged(nameof(TestContextPassing));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM