How to Move focus between Entry fields in .NET MAUI

53463423 60 Reputation points
2024-10-23T23:40:04.7433333+00:00

How can I move the focus back to the previous Entry in .NET MAUI when the current Entry is empty instead of moving forward?

my cursor only goes forward, but I would like it to go back when I delete the entry text.

Developer technologies | .NET | .NET MAUI
0 comments No comments
{count} votes

Answer accepted by question author
  1. Anonymous
    2024-10-24T03:58:01.1533333+00:00

    Hello,

    but I would like it to go back when I delete the entry text."Handling Entry TextChanged event in .NET MAUI

    You can do it by implementing textchanged event and Focus method.

    When this previous Entry's text is empty, you can back to the previous entry by Focus method.

     private void SecondEntry_TextChanged(object sender, TextChangedEventArgs e)
        {
            var entry = sender as Entry;
    
            if (entry.Text.Length == 0)
            {
                entry1.Focus();
    
            }
        }
    

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.