liveBook · Manning

Modal page

As explained in .NET MAUI in Action

A modal page is an application page presented above the current page that requires dismissal before normal navigation continues.

A modal page appears above the current page and requires dismissal before normal navigation continues. Its lack of navigation UI signals that the current task should be completed first. section 8.1.1

Use modal navigation when the user must finish or dismiss a focused task:

  • Push a LoginPage modally when the application starts, rather than registering it as a normal navigable route. section 8.1.1
  • Call PopModalAsync after successful login to reveal the existing Shell. section 8.1.1
  • Remember that Android may still provide a hardware or system back button, unless that behavior is overridden. section 8.1.1

Require login at startup

Override OnStart and call await MainPage.Navigation.PushModalAsync(new LoginPage()). After successful authentication, call await Navigation.PopModalAsync() from LoginPage. section 8.1.1

Listing 8.6 The OnStart functionality to add to App.xaml.cs
protected override async void OnStart()
{
    base.OnStart();
 
    await MainPage.Navigation.PushModalAsync(
 new LoginPage());                             #1
}

Inspect the startup code that pushes LoginPage onto the modal navigation stack. section 8.1.1

How .NET MAUI in Action covers it

How deep it goes
Defines modal behavior, contrasts it with NavigationPage, and demonstrates push/pop methods, but does not detail dismissal overrides.
Examples
Uses a LoginPage pushed at startup and popped after successful login, with Android back-button behavior noted.
What it assumes
Assumes an app with MainPage and LoginPage; teaches how Page.Navigation reaches the application navigation stack.
What you can do after
Apply it via .NET MAUI navigation APIs to present a login page and dismiss it after authentication succeeds.
How it connects
Connects modal pages with application lifecycle, hierarchical navigation, navigation stacks, Shell, and authentication.

This explainer was generated by Manning's knowledge graph from the text of .NET MAUI in Action. The section links point to the parts of the book it draws on.