User Input & Navigation in .NET MAUI
Handling user input and navigating between pages are essential for building interactive, multi-screen apps in .NET MAUI. This guide covers input controls and navigation patterns.
Handling User Input
.NET MAUI provides a range of input controls:
- Entry– for single-line text
- Editor– for multi-line text
- CheckBox,- Switch– for Boolean values
- Picker,- DatePicker,- TimePicker– for selection
Example: Entry Input
<Entry x:Name="nameEntry" Placeholder="Enter your name" />
<Button Text="Say Hi" Clicked="OnButtonClick" />
<Label x:Name="greetingLabel" />
@code {
    private void OnButtonClick(object sender, EventArgs e)
    {
        greetingLabel.Text = $"Hello, {nameEntry.Text}!";
    }
}Page Navigation
Navigate between pages using Navigation.PushAsync():
Step 1: Enable Navigation
Wrap your MainPage in a NavigationPage (in MauiProgram.cs):
builder.Services.AddSingleton<MainPage>();
...
return new App(new NavigationPage(new MainPage()));Step 2: Navigate to Another Page
await Navigation.PushAsync(new SecondPage());Step 3: Back Navigation
To go back:
await Navigation.PopAsync();Passing Data Between Pages
You can pass values via constructor parameters:
// In MainPage.xaml.cs
await Navigation.PushAsync(new SecondPage(userName));
// In SecondPage.xaml.cs
public SecondPage(string userName)
{
    InitializeComponent();
    greetingLabel.Text = $"Hello again, {userName}!";
}MAUI makes it simple to gather user input and move between screens. In the next lesson, we’ll explore how to access device-specific features like GPS, camera, and sensors.
