Hi,
I have a binding issue in my Xamarin.Forms project with the following setup:
- One
GenericPage
superclass inheriting fromContentPage
and containing aBindableProperty
- One
Page
class inheriting fromGenericPage
with aViewModel
which is bound to theBindableProperty
using aOneWayToSource
binding mode - One
GenericControl
superclass inheriting fromContentView
and containing aBindableProperty
- One
Control
class inheriting fromGenericControl
with aControlViewModel
which is bound to theBindableProperty
using aOneWayToSource
binding mode - An instance of the
Control
class is embedded in thePage
class using XAML and theBindableProperty
ofGenericControl
is bound to the property of theViewModel
using aOneWay
binding mode
Visual representation of this setup:
I can verify that the "connection" from Page
to the BindableProperty
of GenericControl
indeed works, as the propertyChanged
method is invoked in GenericControl
with the correct value from the BindableProperty
in GenericPage
. I can also verify that the "connection" from GenericControl
to ControlViewModel
is working (at least in the beginning) as the property setter in ControlViewModel
is called once with the default value from the BindableProperty
in GenericControl
.
However, for some reason, the changes which arrive at the BindableProperty
in GenericControl
(either the default values from GenericPage
or externally set) are not propagated to the ControlViewModel
.
I have created a Repro Project for this issue: github.com/mlxyz/Xamarin-Forms-Binding-Repro
In the project, pressing the button will change the value of the bindable property in GenericPage
. However, the property of the ControlViewModel
is not updated for some reason (the top label).
Why is this the case and how can I fix it?
Thanks!
Note: I have also posted this question to stackoverflow: stackoverflow.com/q/62913492/10289094