Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Bug with databinding a ListView from XAML (leads to big perf problem)

$
0
0

There appears to be a bug in the ordering that BindingContext is set on items generated within a ListView that is causing some invalid debug output. I'm getting debug spew that a binding is failing because a property is not found on the object I'm binding to. But it is not listing the type of object that is being used within my collection pointed to by ItemsSource. It's outputting the type that is in the BindingContext for the ListView... not what should be for the items.
Binding: 'PublishDate' property not found on 'ViewModel', target property: 'Xamarin.Forms.ImageCell.Detail'

The object that is being used on my page is a class called ViewModel and is set as the page's BindingContext. (And is thus also my ListView's BindingContext.)
ViewModel has a property called Articles which is a collection of Article classes.
The Article class has a property called PublishDate.

My ListView has ItemsSource={Binding Articles} so each child item in the list should have a BindingContext set to the item which is type Article.
My DataTemplate for the ListView contains an ImageCell with Detail={Binding PublishDate} which it should be getting from the Article.

So why is the debug spew happening for each of my items which says I'm trying to bind to a PublishDate back on the ViewModel (parent of the Articles)? My guess is that the BindingContext is set on each of the items too late as Xamarin materializes the items and adds children. It looks like its going through the binding code while each child still has BindingContext inherited from the parent (null on itself). I'm guessing that the BindingContext is then getting set after the children are added and the correct binding is getting updated as my view is eventually rendered correct. It's the only way I could envision that my form is showing correct but I'm getting debug spew showing me that I'm binding to the wrong item type (the type my ListView is bound to).

This generate a ton of debug spew while connected to a debugger (I'm using VS2013) and makes the performance unusable until the debug output has completed. I think this is only happening on a page generated from XAML so there may be some timing that coded pages don't exhibit.

More testing and examples using XAML please.


Viewing all articles
Browse latest Browse all 58056

Trending Articles



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