Dialogs

Modal dialogs with OK/Cancel buttons, dimmed background, and async result handling.

Overview

Dialogs are shown via Window.ShowDialogAsync(), which pushes the window onto the application's overlay stack with a dimmed background. Input is restricted to the modal dialog. Setting DialogResult closes it and returns the result.

var dialogWindow = new Window
{
    Width = Size.Absolute(44), Height = Size.Absolute(14),
    Content = new Border
    {
        Background = dialogBg,
        BorderStyle = BorderStyle.Rounded(dialogBorder),
        Child = contentPanel
    }
};

okButton.Click += () => dialogWindow.DialogResult = true;
cancelButton.Click += () => dialogWindow.DialogResult = false;

var result = await dialogWindow.ShowDialogAsync();
// result: true (OK), false (Cancel), null (dismissed)

Key Concepts