New to Telerik UI for .NET MAUI? Start a free 30-day trial
Approach 1: Using
Approach 2: Using
Setting Focus on Entry Using MVVM in UI for .NET MAUI
Updated on Sep 26, 2025
Environment
| Version | Product | Author |
|---|---|---|
| 11.1.0 | Telerik UI for .NET MAUI Entry | Dobrinka Yordanova |
Description
I want to set focus on an Entry control when the page loads using the MVVM (Model-View-ViewModel) approach in UI for .NET MAUI.
This knowledge base article also answers the following questions:
- How to use
EventToCommandBehaviorfor Entry focus in .NET MAUI? - How to use
RadEventToCommandBehaviorfor Entry focus in .NET MAUI? - How to set Entry focus programmatically using MVVM?
Solution
To achieve this, use either the EventToCommandBehavior from CommunityToolkit or RadEventToCommandBehavior from Telerik UI for .NET MAUI.
Approach 1: Using RadEventToCommandBehavior
This approach doesn't require explicitly setting the BindingContext inside the event to command behavior.
-
Add the behavior to the Entry control:
xaml<te:RadEntry.Behaviors> <te:RadEventToCommandBehavior EventName="Loaded" Command="{Binding EntryLoadedCommand}" CommandParameter="{Binding Source={x:Reference Entry}}" /> </te:RadEntry.Behaviors> -
Create a command in your ViewModel:
csharp[RelayCommand] async Task EntryLoaded(object sender) { if (sender is Telerik.Maui.Controls.RadEntry entry) { await MainThread.InvokeOnMainThreadAsync(() => entry.Focus()); } }
Approach 2: Using EventToCommandBehavior from CommunityToolkit
-
Explicitly set the behavior's
BindingContextto the page's ViewModel:xaml<te:RadEntry.Behaviors> <toolkit:EventToCommandBehavior EventName="Loaded" Command="{Binding EntryLoadedCommand}" CommandParameter="{Binding Source={x:Reference Entry}}" BindingContext="{Binding Source={x:Reference MainPage}, Path=BindingContext}" /> </te:RadEntry.Behaviors> -
Add a name to the ContentPage:
xaml<ContentPage x:Name="MainPage" ...> -
Define the command in your ViewModel:
csharp[RelayCommand] async Task EntryLoaded(object sender) { if (sender is Telerik.Maui.Controls.RadEntry entry) { await MainThread.InvokeOnMainThreadAsync(() => entry.Focus()); } }
Both approaches achieve the desired behavior of setting focus on the Entry control when it loads.