Data not Binding in Xamarin Forms - Android App Only.

I have a Xamarin forms App that I have been building and it has been running fine on IOS (SIM and Device). This week I decided to run my App on Android and none of the data binding works.

I have now reduced my ViewModel/Form a very basic message binding to a label, and still the data is not binding for the Android App.

I use Fody.PropertyChange. When I decompile the dll, I can see that the PropertyChanged is getting injected properly.

        public string Message
        {
            [CompilerGenerated]
            get
            {
                return this.<Message>k__BackingField;
            }
            [CompilerGenerated]
            set
            {
                if (string.Equals(this.<Message>k__BackingField, value, StringComparison.Ordinal))
                {
                    return;
                }
                this.<Message>k__BackingField = value;
                this.OnPropertyChanged("Message");
            }
        }

I bind this field to a label on my page <Label Text="{Binding Message}" HorizontalTextAlignment = "Center" />

I have added to to the Page OnAppearing to make sure that the field is being updated

        protected override async void OnAppearing()
        {
            Debug.WriteLine("Payment List Appearing START");

            base.OnAppearing();

            var currentContext = BindingContext as PaymentListViewModel;

            if (currentContext != null)
            {
                Debug.WriteLine("Loading Payments - Started");
                await currentContext.LoadPaymentsFromDb();
                currentContext.Message = "THis is the message " + DateTime.Now.ToString("T");
                Debug.WriteLine("Loading Payments - Done");
            }

            Debug.WriteLine("Payment List Appearing - DONE");
        }

The debug lines confirm that the the viewmodel is ok, and the message is updating correctly, but when running on Android nothing is displayed - yet on IOS, it displays fine.

Does anyone have any ideas on what would cause databinding to fail on Android only.

Sign In or Register to comment.