Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

BindableProperty only updating ViewModel property with default values

$
0
0

Hi,

I have a binding issue in my Xamarin.Forms project with the following setup:

  • One GenericPage superclass inheriting from ContentPage and containing a BindableProperty
  • One Page class inheriting from GenericPage with a ViewModel which is bound to the BindableProperty using a OneWayToSource binding mode
  • One GenericControl superclass inheriting from ContentView and containing a BindableProperty
  • One Control class inheriting from GenericControl with a ControlViewModel which is bound to the BindableProperty using a OneWayToSource binding mode
  • An instance of the Control class is embedded in the Page class using XAML and the BindableProperty of GenericControl is bound to the property of the ViewModel using a OneWay 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


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>