xamarin/Xamarin.Forms

Unfocused issue with Entry in listview

Aperta

#1906 aperta il 17 feb 2018

 (8 commenti) (0 reazioni) (0 assegnatari)C# (1926 fork)batch import
a/listviewe/4 :clock4:help wantedm/high impact :black_large_square:p/Androidt/bug :bug:up-for-grabs

Metriche repository

Star
 (5644 stelle)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

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

Guida contributor