xamarin/Xamarin.Forms

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

オープン

#8,554 opened on 2019/11/18

 (7 件のコメント) (0 件のリアクション) (0 人の担当者)C# (1,926 件のフォーク)batch import
e/3 :clock3:hackathonhelp wantedinactivep/Androidt/bug :bug:up-for-grabs

Repository metrics

Stars
 (5,644 個のスター)
PR merge metrics
 (30d に merged PR はありません)

説明

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

コントリビューターガイド