Back to results for “Navigation”
.NET MAUI › App Lifecycle & Windows

What are the main page lifecycle methods in MAUI?

Beginner

Answer

OnAppearing runs when a page becomes visible (good for loading/refreshing data and subscribing to events) and OnDisappearing when it's navigated away (good for saving state and unsubscribing). They can fire multiple times as the user navigates back and forth, so keep them idempotent.
protected override void OnAppearing()
{
    base.OnAppearing();
    _vm.Load();
}
protected override void OnDisappearing()
{
    base.OnDisappearing();
    _vm.Unsubscribe();
}
Real-world example A dashboard refreshes its data each time the user returns to it via OnAppearing.

Common follow-ups: Do these fire more than once? | Where should you unsubscribe events?