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
Status: RESOLVED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms (show other bugs)
Version: unspecified
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-09-15 01:41 UTC by Melbourne Developer
Modified: 2017-10-04 21:05 UTC (History)
5 users (show)

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

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 FIXED

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.

https://github.com/xamarin/Xamarin.Forms/pull/1150
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.