Xamarin.forms: [Bug] Cannot reuse binding instances

Created on 12 Dec 2019  路  2Comments  路  Source: xamarin/Xamarin.Forms

Description

Greetings,

I am trying to create a single binding instance for a view and want to reuse the same binding instance for similar view to improve performance. While doing so, InvalidOperation exception: "Binding instances can not be reused" has been thrown.

For example:

I have a label element whose text property has some bindings like below.

image

Then I try to use the same binding for some other label's text property as like below.

image

I cannot reuse the same Binding instance as like above. This behavior is not seen in WPF platform. So why is it like this here? Correct me if am doing anything wrong here.

Expected Behavior

Exception should not be thrown.

Actual Behavior

Exception throws when trying to reuse the Binding instance.

Basic Information

  • Version with issue: Latest
  • Last known good version: None
  • IDE: All
unverified bug

All 2 comments

This is not a bug, it is by design. Take a look at the source code and you will see why.
https://github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.Core/Binding.cs
https://github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.Core/BindingBase.cs

And that you get an exception that tells you that you cannot do that is also a thing that shows that this is not a bug. With that said, I don't mean that it is not room for improvements here. But it should not be handled like a bug.

not a bug, Bindings shouldn't be reused. never

Was this page helpful?
0 / 5 - 0 ratings