I've noticed something odd and hoping someone from Xamarin will reply. (NOTE: I understand how to subclass INotifyPropertyChanged and implement the methods so my data binding works both ways. This question is not about how to implement in that manner but whether there is some mechanism in ContentPage that already supports property change notification and what the messages I'm seeing really mean. If I don't need to re-implement something which ContentPage already does, that's a good thing.)
If I create a VM that subclasses ContentPage:
public class MainVM : ContentPage
And then attempt to add my own PropertyChangedEventHandler in that class:
public event PropertyChangedEventHandler PropertyChanged;
Xamarin informs me that my new property "hides inherited member 'BindableObject.PropertyChanged'".
This implies to me that ContentPage (or one of its ancestor classes) already implements a PropertyChangedEventHandler named PropertyChanged. I'm thinking "Great, I don't need to specifically implement the property change notification mechanism as it is handled by ContentPage." And, in fact, if I make no other changes, I can confirm that one-way binding works. Changing a value in the UI updates the property in the VM. However, two-way binding does not work -- the UI is not updated when the VM code updates the property.
Based upon the above message, I expect there would be an available BindableObject property on my VM.
If I implement a method to handle the other side of notification:
private void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
{
if (this.BindableObject.PropertyChanged != null)
{
this.BindableObject.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
Xamarin informs me that my VM "does not contain a definition for 'BindableObject'" even though it is subclassing ContentPage.
So, the messages seem to be giving conflicting information: One says there is an inherited member "BindableObject.PropertyChange" while the other says there is no "BindableObject" member.