Bug 52708 - TwoWay bindings call the source property setter during initialization
Summary: TwoWay bindings call the source property setter during initialization
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 2.3.4
Hardware: PC Windows
: Normal major
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2017-02-23 17:25 UTC by kayle.hinkle
Modified: 2017-06-22 01:16 UTC (History)
3 users (show)

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

sample project (275.82 KB, application/x-zip-compressed)
2017-02-28 21:16 UTC, Jimmy [MSFT]

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 for Bug 52708 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:

Description kayle.hinkle 2017-02-23 17:25:26 UTC
# Steps to reproduce

TwoWay binding in xaml:
<Entry Margin="15,0" Text="{Binding UserName}" Placeholder="User Name" />

property in viewmodel
        public string UserName
            get { return _initialSettings.UserName; }
            set { HandleNewUserName(value); }

# Expected behavior
property getter should be called during initialization
property setter should not be called until the text changes

# Actual behavior
property setter is called immediately after getter
Comment 1 Jimmy [MSFT] 2017-02-23 21:59:28 UTC
Thank you for taking the time to file this report! I will run the code provided in the description to try and confirm this issue and update the report as necessary.
Comment 2 Jimmy [MSFT] 2017-02-28 21:16:41 UTC
Created attachment 20044 [details]
sample project

I created a sample project based on the code you provided however I was not able to reproduce the issue you described. When I ran the project, the getter was called as expected and the setter was not called until I started entering text.

I tested with Forms and 2.3.4-pre2 and both worked as expected. If you are seeing this issue with one of these versions, please attach a project that reproduces the issue so we can look into this further. Thanks!
Comment 3 kayle.hinkle 2017-03-02 20:02:02 UTC
Hi Jimmy, 

I made two small changes to your attached view model to cause the issue. First set _username to a non-empty initial value. Second, remove the if check from the setter. I verified the problem exists at least in iOS project, but expect it to be the same for Android and UWP as well.

    string _username = "initial value";
    public string UserName
        Debug.WriteLine($"****** Getting {nameof(UserName)} ******");
        return _username;
        Debug.WriteLine($"===== Setting {nameof(UserName)} =====");
        _username = value;
Comment 4 Mike Norman 2017-06-20 17:35:28 UTC
This still repros with the changes by kayle.hinkle.