xamarin/Xamarin.Forms

Unfocused issue with Entry in listview

开放

#1,906 创建于 2018年2月17日

 (8 条评论) (0 个反应) (0 位负责人)C# (1,926 个派生)batch import
a/listviewe/4 :clock4:help wantedm/high impact :black_large_square:p/Androidt/bug :bug:up-for-grabs

仓库指标

星标
 (5,644 个星标)
PR 合并指标
 (30 天内没有已合并 PR)

描述

Description

I have a ListView with ViewCells in my ContentPage. Each ViewCell has a CustomEntry (that I have created). I want control if the user leaves the Entry empty. If he leaves the Entry empty, I would like to leave the last value that Entry has had. The easiest solution for me is using Focused and Unfocused events. But the behaviour between events is very strange.

Steps to Reproduce

Tab first CustomEntry Tab second CustomEntry Press Del key of the keyboard You will see that the cursor moves at the beginning of the CustomEntry but it doesn't remove the text.

Expected Behavior

Tap first CustomEntry Fires Focused first CustomEntry event Fires Unfocused first CustomEntry event Tap second CustomEntry Fires Focused second CustomEntry event Fires Unfocused second CustomEntry event

Actual Behavior

Tap first CustomEntry Fires Focused first CustomEntry event Fires Unfocused first CustomEntry event Tap second CustomEntry Press Del key of the keyboard Fires Focused second CustomEntry event Fires Unfocused second CustomEntry event Fires Focused first CustomEntry event Fires Unfocused first CustomEntry event Fires Focused second CustomEntry event The cursor moves at the beginning of the CustomEntry

Basic Information

  • Version with issue: 2.5

  • Last known good version: Don't know

  • IDE: VS2017

  • Platform Target Frameworks:

    • Android: 8.0
  • Affected Devices: All Android

Code

{
    private string oldValue;

    public CustomEntry()
    {
        this.oldValue = "1";            
        this.Focused += CustomEntry_Focused;
        this.Unfocused += CustomEntry_Unfocused;                        
    }

    private void CustomEntry_Focused(object sender, FocusEventArgs e)
    {
        if (this.Text != null)
        {
            this.oldValue = this.Text;
        }  
    }

    private void CustomEntry_Unfocused(object sender, FocusEventArgs e)
    {
        try
        {
            if (this.Text != null) { 
                //If the user leaves the field empty                
                if (this.Text.Trim().Equals(string.Empty))
                {
                    this.Text = this.oldValue;
                }
            }
        }
        catch (FormatException ex) { }
    }
}```

贡献者指南