I am having some problems understanding xaml with mvvm. Sometimes works but others doesn't.
ViewModel (implements INotifyPropertyChanged):
private Class1 firstClass;
public Class1 FirstClass{
get{return firstClass;}
set{firstClass = value; OnPropertyChanged();}
}
private string name;
public string Name{
get{return name;}
set{name = value; OnPropertyChanged();}
}
private string address;
public string Address{
get{return address;}
set{address = value; OnPropertyChanged();}
}
View:
private ViewModel vm;
In the View constructor:
vm = new ViewModel(id);
BindingContext = vm;
OnAppearing (async):
base.OnAppearing();
await vm.LoadDataAsync();
lAddress.SetBinding(Label.TextProperty, new Binding("Address");
If I set the BindingContext in xaml and remove it from the constructor, it does not work.
If I set the Binding on the Address label in xaml and remove it from the code behind, it does not work.
If I try to use Name as the Title of the page, it does not work.
In any of these cases I am not getting any error like 'Binding: property not found on BindingContext' so I understand that they are being found but maybe they are empty.
If I modify a property from Class1, it does not appear on the page. Can I assume that the reason is that Class does not implement INotifyPropertyChanged?
Is it better or advisable to LoadData in VM constructor (Task.Run) or on Page.OnAppearing(await vm.LoadData())?
Could anybody provide a bit of guidance?
EDIT: