Xamarin.forms: False binding error in ListView when ItemsSource and parent BindingContext set

Created on 13 Jan 2018  Â·  6Comments  Â·  Source: xamarin/Xamarin.Forms

Description

When using ListView, if you set its ItemsSource, and also set the parent's BindingContext, the binding engine will report an error that parent couldn't bind to the item property. This is a false error because the parent doesn't need to bind.

The false errors make is very difficult to find actual errors when debugging. I wouldn't be surprised if they hurt production performance, too.

Steps to Reproduce

  1. Run the repro. (This repro is used for two different bugs. That's why the repro name does match this bug.)

Expected Behavior

The app works. No error in the VS Output window.

Actual Behavior

The app works. The following error in the VS Output window:

Binding:'Hello' property not found on 'ClassLibrary1.Page1', target property: 'Xamarin.Forms.TextCell.Text'

Basic Information

  • Version with issue: 2.5.0.122203
  • IDE: Visual Studio
  • Platform Target Frameworks:

    • iOS: Haven't tried.

    • Android: Haven't tried.

    • UWP: 16299

binding ⛓ 2 inactive UWP bug

All 6 comments

UWP does apply the context on the cell itself first, but it doesn't hurt performances.

@StephaneDelcroix My concern wasn't with performance (haven't measured that), but with developer experience. The false error report creates noise that makes it difficult to find real errors. Please reopen and schedule at a priority of other developer experience fixes.

I'm seeing what appears to be the same thing as reported here. I'm using Xamarin.Forms v4.5.0.725.

In my main view code behind constructor, I set the BindingContext to an instance of the view model. In the main view XAML, I have a ListView with its ItemsSource set to an ObservableCollection property in the view model. I have a custom data template defined which uses 2 labels that each have their text property bound to a property on the items stored in the ObservableCollection. The items are themselves observable, implementing INotifyPropertyChanged.

When I run I always get the below (once for each row in the list) when the view starts up.

Binding: 'Name' property not found on 'MyApp.ViewModels.MainViewModel', target property: 'Xamarin.Forms.Label.Text'
Binding: 'Value' property not found on 'MyApp.ViewModels.MainViewModel', target property: 'Xamarin.Forms.Label.Text'

The list appears to work correctly, the data is displayed as expected.

@nerdtronn We are having same issue. We have Xamarin.Forms v4.7
This issue leads us to have be random app crash issue with thread. (not sure although)
Can you share any suggestion or solution for this issue?

Why was this issue close??? I absolutely agree with the OP. Debugging a binding error is difficult enough given the lack of an exception when it happens. The only way to make sure that all the bindings are done right in an complex application is to read the Debug window. If it's polluted with unnecessary bindings, that makes debugging imposible.

As for the issue of performance, of course your performance is going to suffer. You're trying to bind to the parent object before the item for ABSOLUTELY NO REASON.

UWP does apply the context on the cell itself first, but it doesn't hurt performances.

1.) You have completely missed the issue. It's impossible to debug binding issues when your screen is filled up with thousands of these false error messages.
2.) Debugging Binding issues is a critical issue for any production product.
3.) There is no reason for the binding to be implicitly checking the owner of the ItemsSource. This is a bug.
4.) I don't believe this doesn't impact performance. If you have 1000 items in your list with 5 controls that perform binding operations in the list item, you have 5000 operations that do nothing but waste time every time you bring up a list. The performance of Xamarin is no so spectacular that you can afford wasted operations like this.

Was this page helpful?
0 / 5 - 0 ratings