Bug 59507 - Setting BindingContext Doesn't Work if Equality of BindingContext is Equal
Summary: Setting BindingContext Doesn't Work if Equality of BindingContext is Equal
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms (show other bugs)
Version: unspecified
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2017-09-15 01:41 UTC by Melbourne Developer
Modified: 2017-10-04 21:05 UTC (History)
5 users (show)

See Also:
Tags: fr ac
Is this bug a regression?: ---
Last known good build:


Description Melbourne Developer 2017-09-15 01:41:27 UTC
If you set the BindingContext property of BindableObject to a new object (different object reference) but is equal according the Equals method, the BindingContext will not change. The property for changing the method shouldn't even pay attention to the Equals method because it is not relevant, but if you put a breakpoint on Equals method of any BindingContext, you will see that the XF library is checking for equality on the new BindingContext, and then ignoring the new BindingContext if the Equals method returns true.

To reproduce:
-Clone this repo: git clone https://ChristianFindlay@bitbucket.org/ChristianFindlay/xamarin-forms-scratch.git
-Open the solution Test Apps\TestXamarinForms.sln
-Run the UWP sample
-Click the "Binding Context Equality Issue" button
-Notice that the BindingContextEqualityPage_BindingContextChanged event handler is fired
-Click "Change BindingContext Buggy"
-Notice that it calls the Equals method on the model for no reason, and this method returns true because the "Key" property is the same on both models even though the text in "Test" is different
-Click "Change BindingContext OK"
-Notice that the BindingContextEqualityPage_BindingContextChanged event handler is fired because the "Key" property is different between models and therefore the Equals method returns false.
This behaviour is not standard Microsoft bding behaviour. This does not happen in Silverlight, WPF, and UWP.
Comment 1 Stephane Delcroix 2017-09-20 08:38:44 UTC
I can confirm the reported behavior. Changing this is potentially a breaking change, but might be worth it to be aligned with other platforms.

Comment 2 Melbourne Developer 2017-09-20 23:17:44 UTC
Thanks for acknowledging the problem.

While there is a chance that this is a breaking change, currently, people must be writing hack code to work around this. So, it will be worth fixing now so that developers in future don't have to pile hack code on top of hack code to avoid this issue.
Comment 3 Samantha Houts [MSFT] 2017-10-04 16:54:38 UTC
Should be fixed in 2.4.1.-pre1. Thank you!
Comment 4 Melbourne Developer 2017-10-04 21:05:28 UTC
You guys are killing it. Nice work.

Note You need to log in before you can comment on or make changes to this bug.