Bug 36949 - Observable collections bindings not working
Summary: Observable collections bindings not working
Status: RESOLVED NOT_REPRODUCIBLE
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 2.0.0
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-12-13 19:50 UTC by Stacy Henwood
Modified: 2016-03-04 11:28 UTC (History)
4 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Example screenshot (160.11 KB, image/png)
2015-12-13 19:50 UTC, Stacy Henwood
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED NOT_REPRODUCIBLE

Description Stacy Henwood 2015-12-13 19:50:45 UTC
Created attachment 14263 [details]
Example screenshot

Observable collections bound to ListView's do not behave in WinRT (Windows Phone 8.1).

I have a simple listview that has a DataCell template with some items bound to an object.

If the page is navigated to, the user navigates off the page, then back to the page (using the Navigation PushAsync/PopAsync methods) when they return to the page with the bound ObservableCollection the bindings have broken and some item are not displayed. The broken bindings seem to correlate to data that has changed in the observable collection).

Example Listview:

<ListView x:Name="PickupListView" ItemTapped="PickupTapped" VerticalOptions="Fill">
        <ListView.ItemTemplate>
          <DataTemplate>
            <ViewCell>
              <Grid HeightRequest="80" RowSpacing="0">
                <Grid.ColumnDefinitions>
                  <ColumnDefinition Width="30"/>
                  <ColumnDefinition Width="28"/>
                  <ColumnDefinition Width="15"/>
                  <ColumnDefinition Width="1*"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                  <RowDefinition/>
                  <RowDefinition Height="2"/>
                </Grid.RowDefinitions>
                <BoxView BackgroundColor="#014188" Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="4"/>
                <Label Text="{Binding Icon}" Grid.Column="1" Grid.Row="0" FontSize="{Binding IconSize}" FontFamily="/Assets/Fonts/fontawesome-webfont.ttf#FontAwesome" VerticalOptions="Center" TextColor="{Binding IconColor}"/>
                <Grid Grid.Row="0" Grid.Column="3" VerticalOptions="Center" RowSpacing="2" Padding="0,5,0,0">
                  <Label Text="{Binding Description}" TextColor="White" Grid.Column="0" Grid.Row="0" FontSize="{Binding FontSize}" FontFamily="/Assets/Fonts/VAG-Rounded-Std-Light_47298.ttf#Vag Rounded Std" YAlign="End"/>
                  <Label Text="{Binding SubDescription}" TextColor="White" Grid.Column="0" Grid.Row="1" FontSize="{Binding SubFontSize}" FontFamily="/Assets/Fonts/VAG-Rounded-Std-Light_47298.ttf#Vag Rounded Std" YAlign="Start"/>
                </Grid>
              </Grid>
            </ViewCell>
          </DataTemplate>
        </ListView.ItemTemplate>
      </ListView>
Comment 1 Stacy Henwood 2015-12-18 01:34:48 UTC
We have found another bug related to this.

Because the font sizes render differently on WinPhone and WinRT, we have had to bind the font size into the template (as shown above). If we do this, and attempt to clear or remove items from the ObservableCollection, we cause a crash in the ApplyFont method in Xamarin.Forms.Core.dll.

Stack trace is as follows:

at Xamarin.Forms.Platform.WinPhone.FontExtensions.ApplyFont(TextBlock self, Font font)
   at Xamarin.Forms.Platform.WinPhone.LabelRenderer.UpdateFont(TextBlock textBlock)
   at Xamarin.Forms.Platform.WinPhone.LabelRenderer.OnElementPropertyChanged(Object sender, PropertyChangedEventArgs e)
   at System.ComponentModel.PropertyChangedEventHandler.Invoke(Object sender, PropertyChangedEventArgs e)
   at Xamarin.Forms.BindableObject.OnPropertyChanged(String propertyName)
   at Xamarin.Forms.BindableObject.SetValueActual(BindableProperty property, BindablePropertyContext context, Object value, Boolean currentlyApplying, SetValueFlags attributes, Boolean silent)
   at Xamarin.Forms.BindableObject.SetValueCore(BindableProperty property, Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes)
   at Xamarin.Forms.BindableObject.SetValue(BindableProperty property, Object value, Boolean fromStyle, Boolean checkAccess)
   at Xamarin.Forms.BindableObject.SetValue(BindableProperty property, Object value)
   at Xamarin.Forms.Label.set_Font(Font value)
   at Xamarin.Forms.Label.OnFontSizeChanged(BindableObject bindable, Object oldValue, Object newValue)
   at Xamarin.Forms.BindableObject.SetValueActual(BindableProperty property, BindablePropertyContext context, Object value, Boolean currentlyApplying, SetValueFlags attributes, Boolean silent)
   at Xamarin.Forms.BindableObject.SetValueCore(BindableProperty property, Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes)
   at Xamarin.Forms.BindingExpression.ApplyCore(Object sourceObject, BindableObject target, BindableProperty property, Boolean fromTarget)
   at Xamarin.Forms.BindingExpression.Apply(Object sourceObject, BindableObject target, BindableProperty property)
   at Xamarin.Forms.Binding.Apply(Object newContext, BindableObject bindObj, BindableProperty targetProperty)
   at Xamarin.Forms.BindableObject.ApplyBindings(Object oldContext, Boolean skipBindingContext)
   at Xamarin.Forms.BindableObject.ApplyBindings(Object oldContext)
   at Xamarin.Forms.BindableObject.SetInheritedBindingContext(BindableObject bindable, Object value)
   at Xamarin.Forms.Element.OnBindingContextChanged()
   at Xamarin.Forms.View.OnBindingContextChanged()
   at Xamarin.Forms.Grid.OnBindingContextChanged()
   at Xamarin.Forms.BindableObject.SetInheritedBindingContext(BindableObject bindable, Object value)
   at Xamarin.Forms.Element.OnBindingContextChanged()
   at Xamarin.Forms.View.OnBindingContextChanged()
   at Xamarin.Forms.Grid.OnBindingContextChanged()
   at Xamarin.Forms.BindableObject.SetInheritedBindingContext(BindableObject bindable, Object value)
   at Xamarin.Forms.Element.OnBindingContextChanged()
   at Xamarin.Forms.Cell.OnBindingContextChanged()
   at Xamarin.Forms.BindableObject.BindingContextPropertyBindingPropertyChanged(BindableObject bindable, Object oldvalue, Object newvalue)
   at Xamarin.Forms.BindableObject.SetValueActual(BindableProperty property, BindablePropertyContext context, Object value, Boolean currentlyApplying, SetValueFlags attributes, Boolean silent)
   at Xamarin.Forms.BindableObject.SetValueCore(BindableProperty property, Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes)
   at Xamarin.Forms.BindableObject.SetValue(BindableProperty property, Object value, Boolean fromStyle, Boolean checkAccess)
   at Xamarin.Forms.BindableObject.SetValue(BindableProperty property, Object value)
   at Xamarin.Forms.BindableObject.set_BindingContext(Object value)
   at Xamarin.Forms.TemplatedItemsList`2.UnhookItem(TItem item)
   at Xamarin.Forms.TemplatedItemsList`2.OnProxyCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e, Boolean fixWindows)
   at Xamarin.Forms.TemplatedItemsList`2.SplitCollectionChangedItems(NotifyCollectionChangedEventArgs e)
   at Xamarin.Forms.TemplatedItemsList`2.OnProxyCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e, Boolean fixWindows)
   at Xamarin.Forms.TemplatedItemsList`2.OnProxyCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
   at Xamarin.Forms.ListProxy.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
   at Xamarin.Forms.ListProxy.<>c__DisplayClass52_0.<OnCollectionChanged>b__0()
   at Xamarin.Forms.ListProxy.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
   at Xamarin.Forms.ListProxy.WeakNotifyProxy.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
   at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
   at System.Collections.ObjectModel.ObservableCollection`1.ClearItems()
   at System.Collections.ObjectModel.Collection`1.Clear()
   at MadcapMobile2.Pages.RouteDownloadPageOffline.GetMatchingRoutes(Nullable`1 date, String partialDriverName, String partialVehicleRego)
   at MadcapMobile2.Pages.RouteDownloadPageOffline.UpdateRouteList()
   at MadcapMobile2.Pages.RouteDownloadPageOffline.VehicleTextChanged(Object sender, TextChangedEventArgs e)
   at MadcapMobile2.Helpers.EventExtensions.Fire[T](EventHandler`1 eventHandler, Object sender, T args)
   at MadcapMobile2.Pages.Components.IconEntry.Entry_TextChanged(Object sender, TextChangedEventArgs e)
   at Xamarin.Forms.Entry.OnTextChanged(BindableObject bindable, Object oldValue, Object newValue)
   at Xamarin.Forms.BindableObject.SetValueActual(BindableProperty property, BindablePropertyContext context, Object value, Boolean currentlyApplying, SetValueFlags attributes, Boolean silent)
   at Xamarin.Forms.BindableObject.SetValueCore(BindableProperty property, Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes)
   at Xamarin.Forms.BindableObject.SetValueCore(BindableProperty property, Object value, SetValueFlags attributes)
   at Xamarin.Forms.Element.Xamarin.Forms.IElementController.SetValueFromRenderer(BindableProperty property, Object value)
   at Xamarin.Forms.Platform.WinPhone.EntryRenderer.TextBoxOnTextChanged(Object sender, TextChangedEventArgs textChangedEventArgs)
   at MS.Internal.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
   at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)
Comment 2 Stacy Henwood 2015-12-18 02:22:18 UTC
Whoops, it should be in the Xamarin.Forms.Platform.WP8.dll, not the Xamarin.Forms.Core.dll.
Comment 3 Rui Marinho 2016-01-28 18:40:40 UTC
Needs Info
Thank you for taking the time to submit the bug. We tried to reproduce the issue you reported but were unable given the description. If you could please attach a reproduction to the bug by starting with a clean Xamarin.Forms project and adding just the code necessary to demonstrate the issue we would very much appreciate it.

Warm regards,
Xamarin Forms Team
Comment 4 Stacy Henwood 2016-03-04 01:43:50 UTC
Sorry for the delay in replying. I attempted to create a clean project as requested, but now I find that I cannot emulate this either. 

I'm happy to tentatively mark this as unreproducible.
Comment 5 Rui Marinho 2016-03-04 11:28:58 UTC
Per user comment marking as unreproducible.