Dialogs

Present native alerts, confirmations, prompts, and action sheets through navigation.

INavigator presents native dialogs from the active page. Inject it into the view model or service that owns the interaction.

The same navigator handles navigation stacks and modals.

public sealed class ProjectViewModel(INavigator navigator)
{
    public async Task DeleteAsync()
    {
        bool accepted = await navigator.ConfirmAsync(
            "Delete project?",
            "This cannot be undone.",
            accept: "Delete",
            destructive: true);

        if (accepted)
            await DeleteProjectAsync();
    }
}

AlertAsync displays a message and one dismiss action. ConfirmAsync returns true only for the accept action. Mark the accept action destructive when it removes or discards data.

Prompts and choices

PromptAsync presents one short text field and returns the entered string, or null when canceled:

string? name = await navigator.PromptAsync(
    "Rename project",
    "Choose a new name.",
    placeholder: "Project name",
    text: currentName,
    accept: "Rename");

Use a full page or modal form when input needs validation messages, multiple fields, secure entry, or supporting controls.

SelectAsync presents an action sheet. Plain strings convert to ordinary DialogOption values; construct an option explicitly to mark it destructive:

string? choice = await navigator.SelectAsync(
    "Export format",
    "Cancel",
    "PDF",
    "Markdown",
    new DialogOption("Remove exported files", isDestructive: true));

The result is the chosen option's text or null. If text is not a stable application identifier, map options immediately rather than storing the returned label as domain state.