xamarin/Xamarin.Forms

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

开放

#8,554 创建于 2019年11月18日

 (7 条评论) (0 个反应) (0 位负责人)C# (1,926 个派生)batch import
e/3 :clock3:hackathonhelp wantedinactivep/Androidt/bug :bug:up-for-grabs

仓库指标

星标
 (5,644 个星标)
PR 合并指标
 (30 天内没有已合并 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

贡献者指南