Dialog Service

Open Home → Controls gallery → Dialogs, select Expanded, then open MarkdownDetailsDialog. The title and action buttons remain outside the scrolling body.
IDialogService provides access to registered dialog prefabs. Use the extension methods in Asv.Avalonia to open standard dialogs with ordinary arguments instead of constructing a payload. Call them from the UI thread, for example from a view model command, and await the result.
Confirmation
The result is true for Yes, false for No, and null when dismissed without a choice. Check == true before applying an action that requires confirmation.
Standard dialogs
All methods below are extensions of IDialogService. Return types include the asynchronous task.
Method | Required arguments | Result |
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ShowSaveCancelDialogAsync currently combines Don't Save and dismissal into false. ShowUnsavedChangesDialogAsync also returns false for both No and dismissal. The file picker methods choose paths; they do not read or write the selected files.
Optional arguments specific to each dialog:
HotKeyCapture:
currentHotKey.OpenFile:
typeFilter,initialDirectory.SaveFile:
defaultExt,suggestedFileName,typeFilter,initialDirectory.SelectFolder:
oldPath.
Icon, frame color, and size
The six standard prefabs that create ContentDialog, and both GeoMap prefabs, accept the following optional arguments. Their payloads expose the matching properties.
Argument / property | Type | Behavior |
|---|---|---|
|
| Icon to the left of the title; |
|
| Asv palette color; defaults to |
|
| Frame color, independent of the icon color |
|
| Dialog sizing; defaults to |
The frame uses SystemAccentColorDark3 in the normal state, AsvForegroundWarningBrush for Warning, and AsvForegroundErrorBrush for Error. Success currently uses the normal frame color. The title and button panel remain visible while the content scrolls. The close button at the top right dismisses the dialog without a choice, like Escape; for YesOrNo this returns null.
Prefab | Default icon | Default status |
|---|---|---|
YesOrNo |
|
|
SaveCancel |
|
|
Input |
|
|
HotKeyCapture |
|
|
MarkdownDetails |
|
|
UnsavedChanges |
|
|
EditApiKey (GeoMap) |
|
|
GeoPoint (GeoMap) |
|
|
A directly constructed ContentDialog defaults to Icon = null, IconColor = None, Status = Normal, and SizeMode = Compact. Prefabs supply the defaults listed above. System file and folder pickers use operating-system styling and do not accept these appearance arguments.
Size modes
Mode | Width | Height |
|---|---|---|
| Content-sized, limited to 320–548 | Content-sized, limited to 184–756 |
| Fills the available width | Content-sized, limited to 756 |
| Fills the available width | Fills the available height |
Dimensions are Avalonia logical units. Compact preserves the existing outer margin of 100. Wide and Expanded leave a margin of 60 on every side and follow window resizing. In Wide and Expanded, the action buttons are grouped at the right edge and share the width required by the longest label. Compact retains its existing stretched button layout. The dimensions and margins are supplied by the dialog theme resources. The older FullSizeDesired property remains available; it stretches vertically within the existing limits. Prefer SizeMode for new callers.
Markdown details
markdownText is rendered by the native MarkdownViewer; originalText is copied when the user chooses Copy details. Supported formatting includes headings of levels 1–3, paragraphs, flat bullet and numbered lists, bold text, Material icon tokens, Asv color spans, and escaped formatting markers. This viewer does not support general HTML, tables, links, images, or fenced code blocks.
GeoMap dialogs
Add using Asv.Avalonia.GeoMap; to access the GeoMap extensions. The corresponding module must register its dialog prefabs.
GeoPoint returns GeoPoint?, with null on cancellation. EditApiKey returns string?; cancelling preserves the supplied key, while accepting an empty key returns null.
Registration and custom prefabs
RegisterDialogs() registers the standard prefabs when no configuration callback is supplied. A custom callback replaces that default registration, so call RegisterDefault() explicitly when adding your own prefab alongside the standard ones:
Extensions obtain the registered prefab and construct its payload internally. GetDialogPrefab<T>() and TryGetDialogPrefab<T>() remain available for custom prefabs and optional registrations. The existing YesOrNoDialogPrefab.ShowDialogAsync(payload) returns Task<bool> for compatibility; use ShowDialogResultAsync(payload) or the service extension to distinguish dismissal from No.
See Dialogs and Notifications for a custom DialogViewModelBase and prefab implementation. The example application's dialog gallery demonstrates all ten standard dialogs and both GeoMap dialogs. Its SizeMode selector applies Compact, Wide, or Expanded to the custom dialog and all ContentDialog prefab examples, including Markdown details. The gallery initially selects Compact; system file and folder dialogs keep their native sizing.