xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.62k stars 1.87k forks source link

Binding a collection to a Bindable property of CustomView gives null value #4266

Open DeepikaBalaSubramaniyan opened 5 years ago

DeepikaBalaSubramaniyan commented 5 years ago

Description

We would like to bring to your notice a bug that we encountered recently, while binding a collection to CustomView Bindable property in XAML page, gives null value in OnBindablePropertyChangedMethod(). We have reproduced this issue by writing CustomView derived from Grid Layout, and binding a collection to this CustomView Bindable property in XAML page. Following points happened while hit the break points in OnBindablePropertyChangedMethod().

  1. While first time flow at newValue we get count 0 from constructor of CustomView.
  2. At second time we are getting null value from InitializeComponent().
  3. At third time we able to get the binding collection item count.

Getting null value at second time flow, was making issue in our Control, So Check and provide a solution at second time hit itself, Is it possible to get bindable collection count in newValue param. Issue was with all Xamarin Forms all platforms. Also I would like to mention binding a collection in code behind file, OnBindablePropertyChanged() newValue param does not have any null value at any time hits. Issue was only while using XAML Page.

Steps to Reproduce

  1. Run the attached sample
  2. Hits the break point in OnBindablePropertyChanged().
  3. Please note a newValue param in this method at second time hit, The value was null.

Note : Already we have reported above mentioned issue in git-hub, But unfortunately due to sample issue, report was closed by Xamarin team, This time we have attached the correct reproduction sample.

Expected Behavior

The newValue param should not be null at second time hit in OnBindablePropertyChanged(), we want bindable collection item count instead of null value.

Actual Behavior

The newValue param has null value at second time hit in OnBindablePropertyChanged().

Basic Information

Reproduction Sample Link

GridNotLoade_GitHub.zip

pauldipietro commented 5 years ago

The behavior appears to occur as described (value of 0 and then null before another non-null value) using the reproduction, as well as against the 3.4-pre.