xamarin/Xamarin.Forms

Bound Entry CursorPosition value different between UWP and Android after TextChanged event

Ouverte

#8 554 ouverte le 18 nov. 2019

 (7 commentaires) (0 réaction) (0 personne assignée)C# (1 926 forks)batch import
e/3 :clock3:hackathonhelp wantedinactivep/Androidt/bug :bug:up-for-grabs

Métriques du dépôt

Stars
 (5 644 étoiles)
Métriques de merge PR
 (Aucune PR mergée en 30 j)

Description

Description

When rising a Entry TextChanged event, if CursorPosition is bound to the behavior, the value is different on UWP and Android device.

Steps to Reproduce

  1. attache entry TextChanged to a behavior
  2. bind CursorPosition to a behavior property
  3. run on UWP and Android device

xaml

           <Entry x:Name="EntryAltitude"
                   Text="{Binding Altitude}"
                   CursorPosition="{Binding AltitudeCursorPosition}">
                <Entry.Behaviors>
                    <behaviors:AltitudeEntryBehavior BCursorPosition="{Binding Source ={x:Reference EntryAltitude},
                                                                               Path=CursorPosition,Mode=TwoWay}"/>
                </Entry.Behaviors>
            </Entry>

behavior:

    public class AltitudeEntryBehavior : BehaviorBase<Entry>
    {
        public static readonly BindableProperty BCursorPositionProperty =
        BindableProperty.CreateAttached("BCursorPosition", typeof(int), typeof(AltitudeEntryBehavior), 0,BindingMode.TwoWay);
        public int BCursorPosition
        {
            get { return (int)GetValue(BCursorPositionProperty); }
            set { SetValue(BCursorPositionProperty, value); }
        }
        private void OnEntryTextChanged(object sender, TextChangedEventArgs args)
        {
                int cp = Convert.ToInt32(BCursorPosition); // different on UWP and Android

some information there: https://forums.xamarin.com/discussion/174627/how-to-get-the-entry-cursorposition-in-a-textchange-behavior#latest

Expected Behavior

CursorPosition should be the same on any device

Actual Behavior

on Android, the CursorPosition is before the text has changed (emulator and device) on UWP, the CursorPosition is after the text has changed.

Basic Information

  • Version with issue: Xamarin.Forms 4.3.0.947036
  • Last known good version:
  • IDE: VS 2019 16.3.5
  • Platform Target Frameworks:
    • Android: 9.0
    • UWP: 16299
  • Nuget Packages: Xamarin.Forms 4.3.0.947036
  • Affected Devices:
    • Huawei ANE-LX1
    • Emulator Oreo 8.0

Guide contributeur