-
-
Notifications
You must be signed in to change notification settings - Fork 77
Custom modal and non‐modal dialogs
Dialogs in WPF that don't inherit from Window
are called custom dialogs. These custom dialogs are supported, but in order for DialogService
to know how to interact with them, you will have to implement a specific interface.
The properties and methods of the interface is a subset of the Window
API, and those familiar with WPF should be familiar with their purpose.
/// <summary>
/// Interface describing a window.
/// </summary>
/// <remarks>
/// This interface is intended for use when custom windows, i.e. windows not
/// inheriting from <see cref="Window"/>, should be shown.
/// </remarks>
public interface IWindow
{
/// <summary>
/// Gets or sets the data context for an element when it participates in data binding.
/// </summary>
object DataContext { get; set; }
/// <summary>
/// Gets or sets the dialog result value, which is the value that is returned from
/// the <see cref="ShowDialog" /> method.
/// </summary>
/// <value>
/// The default is false.
/// </value>
bool? DialogResult { get; set; }
/// <summary>
/// Gets or sets the <see cref="ContentControl"/> that owns this
/// <see cref="IWindow"/>.
/// </summary>
ContentControl Owner { get; set; }
/// <summary>
/// Opens a window and returns only when the newly opened window is closed.
/// </summary>
/// <returns>
/// A <see cref="Nullable{Boolean}"/> value that specifies whether the activity was
/// accepted (true) or canceled (false). The return value is the value of the
/// <see cref="DialogResult"/> property before a window closes.
/// </returns>
bool? ShowDialog();
/// <summary>
/// Opens a window and returns without waiting for the newly opened window to close.
/// </summary>
void Show();
}
The difference between showing a modal dialog inheriting from Window
or a modal custom dialog inheriting from IWindow
is that the latter requires you to call IDialogService.ShowCustomDialog<T>
instead of IDialogService.ShowDialog<T>
.
The code required for showing a modal dialog is exactly the same indifferent of whether the dialog is inheriting from Window
or IWindow
.
The difference between showing a non-modal dialog inheriting from Window
or a non-modal custom dialog inheriting from IWindow
is that the latter requires you to call IDialogService.ShowCustom<T>
instead of IDialogService.Show<T>
.
The code required for showing a non-modal dialog is exactly the same indifferent of whether the dialog is inheriting from Window
or IWindow
.
Introduction
Dialog types
- Modal and non‐modal dialogs
- Message box
- Open file dialog
- Save file dialog
- Folder browser dialog
- Custom modal and non‐modal dialogs
- Custom message box
- Custom open file dialog
- Custom save file dialog
- Custom folder browser dialog
Configuration
Advanced usage