Bug 58823 - NativeBindingExtensions SetBinding Android EditText moves caret to start when text changes
Summary: NativeBindingExtensions SetBinding Android EditText moves caret to start when...
Alias: None
Product: Forms
Classification: Xamarin
Component: Android ()
Version: 2.3.4
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2017-08-16 19:32 UTC by Diego
Modified: 2017-08-18 19:08 UTC (History)
2 users (show)

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

Sample project (457.98 KB, application/x-zip-compressed)
2017-08-16 19:32 UTC, Diego

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:

Description Diego 2017-08-16 19:32:58 UTC
Created attachment 24250 [details]
Sample project

Good day Xamarin support team.

We are trying to implement a native view in Android but linking with a ViewModel in a PCL using Xamarin Forms binding.
Although using SetBinding from NativeBindingExtensions seems straightforward, when I bind to an EditText, the viewmodel get notified of property updates but the caret is moved always to the start, such is a wrong behaviour.

The attached project shows how while I am tapping the softkeyboard in an EditText the caret is always at start.

The login form of the project is just an example. We are trying to achieve this because of PM requirements to an existing Xamarin Forms project, so if there is a better way to get native UI using Xamarin Forms binding, without using other MVVM framework, with native Android widgets and existing viewmodels, we are open to options.
Comment 1 Jimmy [MSFT] 2017-08-18 19:08:53 UTC
Hey Diego, 

When you set the bindings on the native EditText controls, do not pass in an updateSourceEventName parameter, e.g:

> editTextPhoneNumber.SetBinding(nameof(EditText.Text), new Binding(nameof(LoginPageViewModel.PhoneNumber), BindingMode.TwoWay));

By doing not doing this, the carat remains at the end of the text as expected. Since you are already subscribed to the control's TextChanged event, the handler is running twice and that might be causing the carat to be "reset" in this case.

Hope this helps!