Language

IModalNavigationPlatform Interface

Definition

Presents and dismisses modal pages for a single Window.

public interface class IModalNavigationPlatform : IDisposable
public interface IModalNavigationPlatform : IDisposable
type IModalNavigationPlatform = interface
    interface IDisposable
Public Interface IModalNavigationPlatform
Implements IDisposable
Implements

Remarks

Register an IModalNavigationPlatformFactory in the application's service collection to supply an implementation. This is the extensibility point that lets an alternative platform backend render modal navigation without forking the framework: the framework keeps ownership of the cross-platform modal stack, page lifecycle events and the push/pop reconciliation loop, and only the visual presentation is delegated here.

The framework creates one instance per window and disposes it when the window is destroyed or when the window's handler changes. Implementations must therefore tolerate multiple create/dispose cycles and must not be shared between windows.

All members are invoked on the UI thread.

Dismissals that start on the platform. When the user dismisses a modal natively β€” an interactive swipe-to-dismiss, a hardware back press, a native close button β€” the framework does not observe it. The implementation must route it back through host.Window.Navigation.PopModalAsync() so the cross-platform modal stack and the page lifecycle events stay in sync. The framework then calls PopModalAsync(Page, Boolean) for that page as part of applying the pop, so PopModalAsync(Page, Boolean) must be idempotent and complete successfully when the native modal is already gone.

Disposal. Dispose() is called when the window is destroyed and when the window's handler changes. The framework does not call PopModalAsync(Page, Boolean) for modals that are still presented at that point, so Dispose() is solely responsible for dismissing and releasing every native modal the backend still owns. Do not assume MauiContext, the window handler, or any platform view obtained through them is still usable there β€” teardown may already have disposed the window's service scope. Capture whatever cleanup needs while the instance is live and treat disposal as best effort. A disposed instance is never reused; a new one is created from the factory if the window gets a new handler. Exceptions thrown from Dispose() are logged and do not interrupt window teardown or handler replacement.

Properties

Name Description
IsReady

Gets a value indicating whether the backend can present or dismiss a modal right now.

Methods

Name Description
PageAttached()

Called when the window's page gets a handler, including when the page is replaced.

PopModalAsync(Page, Boolean)

Dismisses modal, revealing CurrentPlatformPage.

PushModalAsync(Page, Boolean)

Presents modal on top of CurrentPlatformPage.

Applies to