xamarin/Xamarin.Forms

Unfocused issue with Entry in listview

Ouverte

#1 906 ouverte le 17 févr. 2018

 (8 commentaires) (0 réaction) (0 personne assignée)C# (1 926 forks)batch import
a/listviewe/4 :clock4:help wantedm/high impact :black_large_square:p/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

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) { }
    }
}```

Guide contributeur