Share via

Focus last entry on enter

Eduardo Gomez 4,316 Reputation points
2026-04-13T17:34:34.0766667+00:00

I have a shopping list app, when you can create, share and view.

From the home screen, go can go to detail screen, where you can input new product, you can click on the plus icon to insert a new row.

What I want to do:

When I click on the plus button and insert a new row, I want to focus the new Borderless Entry. Additionally, I want to press enter, or return and create an end empty row and focus the entry

Github

https://github.com/eduardoagr/ShareCart

Since QA doesn't like my code, I am posting the github

Developer technologies | .NET | .NET MAUI
0 comments No comments

1 answer

Sort by: Most helpful
  1. Surya Amrutha Vaishnavi Lanka (INFOSYS LIMITED) 1,960 Reputation points Microsoft External Staff
    2026-04-15T12:40:29.73+00:00

    Thanks for reaching out
    In a CollectionView, each Entry is inside a DataTemplate and is created/recycled by virtualization. That makes it hard to directly reference and call Focus() on “the newly added row’s Entry”.

    A common workaround is: drive focus from the ViewModel via a bindable property, and let the custom Entry focus itself when that property becomes true. This pattern is shown as a workaround for “focus next Entry in CollectionView” scenarios.

    1. Create a custom Entry that focuses itself when a bindable flag becomes true Create something like MyEntry you can apply the same idea to your existing BorderlessEntry control
    2. Add a “ShouldFocus” property to each row or item in your list. public class ShoppingRow : ObservableObject // or INotifyPropertyChanged {     private string _text;     public string Text     {         get => _text;         set => SetProperty(ref _text, value);     }     private bool _shouldFocus;     public bool ShouldFocus     {         get => _shouldFocus;         set => SetProperty(ref _shouldFocus, value);     } } In MAUI, pressing Enter/Return triggers the Entry completion flow (commonly handled via Completed / Return command patterns). This is also the reason the CommunityToolkit provides a focus-on-complete behavior.
    3. When you press Enter/Return, add a new row and focus it code-behind Entry_Completed, or MVVM command (preferred) void Entry_Completed(object sender, EventArgs e) {     if (BindingContext is YourViewModel vm)         vm.AddRowAndFocus(); } Your repo already has a custom BorderlessEntry control folder. So you can implement the same IsExpectedToFocus bindable property inside your BorderlessEntry instead of creating FocusableEntry separately. That keeps your styling intact while enabling reliable focusing.

    "Please try the steps shared above and let me know if this resolves the issue.

    If it works, you may mark this reply as the Accepted Answer — this helps other customers with similar questions find the solution faster."


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.