xamarin/Xamarin.Forms

Unfocused issue with Entry in listview

オープン

#1,906 opened on 2018/02/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

Repository metrics

Stars
 (5,644 個のスター)
PR merge metrics
 (30d に merged 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) { }
    }
}```

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