Bug 60113 - Two-way bindings not working as expected if path is "."
Summary: Two-way bindings not working as expected if path is "."
Status: RESOLVED ANSWERED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 2.4.0
Hardware: All All
: --- normal
Target Milestone: ---
Assignee: Stephane Delcroix
URL:
Depends on:
Blocks:
 
Reported: 2017-10-11 06:55 UTC by René
Modified: 2017-10-12 12:22 UTC (History)
4 users (show)

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


Attachments
test project (59.10 KB, application/zip)
2017-10-11 06:55 UTC, René
Details


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 ANSWERED

Description René 2017-10-11 06:55:39 UTC
Created attachment 25266 [details]
test project

Attached is a demo project and here's a link to a video showing the problem in detail: https://www.youtube.com/watch?v=YpvZv8JFHV0

Repro steps:

* Create a XAML based ContentPage with an entry field
* Add a public string property to the page
* Create a binding to the TextProperty in code behind
* Assign some value to the property

Case 1: set the page ("this") as the binding context and use the name of the public prop as the path
Case 2: set the property itself as the binding context and set the path to "."

Issue:
In both cases the assigned value gets transferred from the model to the UI as expected. 
However, changing the entry fields's content will not update the property in case 2.

Expected:
Both cases should work identically and support two-way bindings.
Comment 1 Mark Smith 2017-10-11 13:23:43 UTC
To add a bit of information to this. Since the property isn't raising INPC, we don't expect it to flow from source to target. 

However, what we are seeing is that it doesn't flow from target to source if we use self bindings. It appears the setter for the property is never called when the Entry is changed in the UI in that case.
Comment 3 Stephane Delcroix 2017-10-12 12:14:20 UTC
You have to think about how Bindings works. By declaring

  <Entry Text="{Binding Foo}" />

you ask the binding system to bind to the property 'Foo' on the BindingContext object. That 'Foo' property exist and has set_Foo() and get_Foo() method defined. When the entry change, the binding system will use set_Foo() to set the value to the model. And all is as it should be

On the other hand, when you do

  <Entry Text="{Binding}" />

or

  <Entry Text="{Binding .}" />

you ask the binding system to bind to the current BindingContext object. The binding system can infer its type, get its value and even converts it just fine, that's why the original value is propagated from the model to the entry. But when the entry changes, the binding system is unable to figure any way to change the value, as you're not giving it an actual property, and so, no setter.
Comment 4 Mark Smith 2017-10-12 12:22:21 UTC
Ah, right - it's not a property when assigned directly, it's just a string value. Thanks Stephane, that makes sense.