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.

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,580 questions
0 comments No comments
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 76,391 Reputation points Microsoft Vendor
    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 Answers by the question author, which helps users to know the answer solved the author's problem.