Table of Contents

Class Dialog

Namespace
PluginUI
Assembly
PluginUI.dll

Modal dialog drawn inside the host window: title, body element and a row of buttons. Enter chooses the default button, Escape the cancel button. Plug-in editors cannot rely on native modal windows (they would block the DAW), so dialogs are popups: the rest of the editor is dimmed and inert while one is open.

public class Dialog : Popup
Inheritance
Dialog
Derived
Inherited Members

Examples

Dialog.ShowMessage(host, "Reset preset", "Discard your changes?", MessageBoxButtons.YesNo,
    r => { if (r == MessageBoxResult.Yes) ResetPreset(); });

Constructors

Dialog()

Creates an empty dialog (add a body with Content and buttons with AddButton(string, object?, bool, bool)).

public Dialog()

Dialog(string?, UIElement?)

Creates a dialog with a title and a body.

public Dialog(string? title, UIElement? body = null)

Parameters

title string
body UIElement

Properties

ButtonCaptions

Captions of the buttons added with AddButton(string, object?, bool, bool), from left to right.

public IReadOnlyList<string> ButtonCaptions { get; }

Property Value

IReadOnlyList<string>

Content

Body element (hides Content: the dialog manages its own children).

[Browsable(false)]
public UIElement? Content { get; set; }

Property Value

UIElement

DialogWidth

Preferred width of the dialog.

public float DialogWidth { get; set; }

Property Value

float

Result

Result chosen by the user (null until a button is chosen).

[Browsable(false)]
public object? Result { get; }

Property Value

object

Title

Title (null = none).

public string? Title { get; set; }

Property Value

string

Methods

AddButton(string, object?, bool, bool)

Adds a button (fluent). The default button reacts to Enter, the cancel button to Escape.

public Dialog AddButton(string text, object? result, bool isDefault = false, bool isCancel = false)

Parameters

text string
result object
isDefault bool
isCancel bool

Returns

Dialog

ArrangeOverride(Rect)

Arranges children inside the final bounds.

protected override void ArrangeOverride(Rect bounds)

Parameters

bounds Rect

Close(object?)

Chooses a result and closes the dialog.

public void Close(object? result)

Parameters

result object

MeasureOverride(Size)

Natural size of the content for the available size (margins excluded).

protected override Size MeasureOverride(Size available)

Parameters

available Size

Returns

Size

OnAttached()

Called when the element joins a host (subscribe to external events here).

protected override void OnAttached()

OnKeyDown(KeyEventArgs)

Keyboard routed to the popup when CapturesKeyboard is set; Escape closes by default.

protected override void OnKeyDown(KeyEventArgs e)

Parameters

e KeyEventArgs

OnRender(DrawingContext)

Draws the element (below its children).

protected override void OnRender(DrawingContext dc)

Parameters

dc DrawingContext

ShowMessage(UIHost, string, string, MessageBoxButtons, Action<MessageBoxResult>?)

Shows a message box. Returns the dialog (already open).

public static Dialog ShowMessage(UIHost host, string title, string message, MessageBoxButtons buttons = MessageBoxButtons.OK, Action<MessageBoxResult>? callback = null)

Parameters

host UIHost
title string
message string
buttons MessageBoxButtons
callback Action<MessageBoxResult>

Returns

Dialog

Events

ResultChosen

Raised when a button is chosen (before the dialog closes).

public event Action<Dialog, object?>? ResultChosen

Event Type

Action<Dialog, object>