ContentDialog
- Assembly:
Fluence.Wpf - Namespace:
Fluence.Wpf.Controls
public class ContentDialog : ContentControl
A modal dialog with a title area, arbitrary body content, and up to three command buttons, mirroring the WinUI 3 ContentDialog control. While open the dialog sits above a smoke layer that dims and blocks everything behind it: over a window that exposes a full-window overlay host (a FluenceWindow PART_DialogOverlayHost) the smoke covers the entire window, title bar included; over a plain window it is hosted in the content adorner layer. A tunneling input guard additionally blocks any press outside the dialog. The owner's visual tree is never restructured. The body uses the inherited Content and ContentTemplate.
Base type: ContentControl (including inherited WPF and .NET members)
Constructors
ContentDialog
public ContentDialog()
Initializes a new instance of the ContentDialog class. The dialog starts collapsed so a dialog declared in window XAML renders nothing inline at rest; it becomes visible while it is hosted in its modal overlay during ShowAsync and collapses again when it closes. SetCurrentValue keeps an explicit consumer-set Visibility authoritative.
Properties
CloseButtonCommand
public ICommand? CloseButtonCommand { get; set; }
Gets or sets the command executed when the close button is invoked (or the dialog is dismissed with the Escape key) and the CloseButtonClick event is not canceled.
CloseButtonCommandParameter
public object? CloseButtonCommandParameter { get; set; }
Gets or sets the parameter passed to CloseButtonCommand.
CloseButtonText
public string CloseButtonText { get; set; }
Gets or sets the text of the close button. The button is collapsed while the text is empty.
DefaultButton
public ContentDialogButton DefaultButton { get; set; }
Gets or sets which command button receives initial keyboard focus when the dialog opens and is invoked by the Enter key while focus is not on another command button.
IsPrimaryButtonEnabled
public bool IsPrimaryButtonEnabled { get; set; }
Gets or sets a value indicating whether the primary button is enabled.
IsSecondaryButtonEnabled
public bool IsSecondaryButtonEnabled { get; set; }
Gets or sets a value indicating whether the secondary button is enabled.
PrimaryButtonCommand
public ICommand? PrimaryButtonCommand { get; set; }
Gets or sets the command executed when the primary button is invoked and the PrimaryButtonClick event is not canceled.
PrimaryButtonCommandParameter
public object? PrimaryButtonCommandParameter { get; set; }
Gets or sets the parameter passed to PrimaryButtonCommand.
PrimaryButtonText
public string PrimaryButtonText { get; set; }
Gets or sets the text of the primary button. The button is collapsed while the text is empty.
SecondaryButtonCommand
public ICommand? SecondaryButtonCommand { get; set; }
Gets or sets the command executed when the secondary button is invoked and the SecondaryButtonClick event is not canceled.
SecondaryButtonCommandParameter
public object? SecondaryButtonCommandParameter { get; set; }
Gets or sets the parameter passed to SecondaryButtonCommand.
SecondaryButtonText
public string SecondaryButtonText { get; set; }
Gets or sets the text of the secondary button. The button is collapsed while the text is empty.
Title
public object? Title { get; set; }
Gets or sets the title shown at the top of the dialog.
TitleTemplate
public DataTemplate? TitleTemplate { get; set; }
Gets or sets the template used to display Title.
Methods
Hide
public void Hide()
Closes the dialog with None. Does nothing when the dialog is not open.
OnApplyTemplate
public override void OnApplyTemplate()
Documentation inherited from the ContentControl API.
OnCreateAutomationPeer
protected override AutomationPeer OnCreateAutomationPeer()
Documentation inherited from the ContentControl API.
OnKeyDown
protected override void OnKeyDown(KeyEventArgs e)
Documentation inherited from the ContentControl API.
Remarks: The Enter/DefaultButton shortcut runs on the bubbling key event (not the tunneling preview) so focused body controls that consume Enter themselves, such as an AcceptsReturn TextBox or an open ComboBox, win over the default button.
OnPreviewKeyDown
protected override void OnPreviewKeyDown(KeyEventArgs e)
Documentation inherited from the ContentControl API.
ShowAsync
public Task<ContentDialogResult> ShowAsync()
Shows the dialog modally over the active window (or the application main window) and returns a task that completes with the ContentDialogResult once the dialog closes. While open, a smoke layer dims the owner window content and blocks mouse input, Tab navigation is trapped inside the dialog, Escape dismisses as if the close button were invoked, and Enter invokes DefaultButton. Must be called on the dialog's dispatcher thread.
Returns: A task that completes with the dialog result when the dialog closes.
Exception System.InvalidOperationException: This dialog or another dialog on the same owner is already open, no owner window could be resolved, the owner window has no UIElement content root, or no adorner layer exists above the owner window content.
Events
CloseButtonClick
public event EventHandler<ContentDialogButtonClickEventArgs>? CloseButtonClick
Occurs when the close button is invoked or the dialog is dismissed with the Escape key. Set Cancel to true to keep the dialog open and skip CloseButtonCommand.
Closed
public event EventHandler<ContentDialogClosedEventArgs>? Closed
Occurs after the dialog has been removed from the owner window's adorner layer.
Opened
public event EventHandler<ContentDialogOpenedEventArgs>? Opened
Occurs after the dialog has been added to the owner window's adorner layer.
PrimaryButtonClick
public event EventHandler<ContentDialogButtonClickEventArgs>? PrimaryButtonClick
Occurs when the primary button is invoked. Set Cancel to true to keep the dialog open and skip PrimaryButtonCommand.
SecondaryButtonClick
public event EventHandler<ContentDialogButtonClickEventArgs>? SecondaryButtonClick
Occurs when the secondary button is invoked. Set Cancel to true to keep the dialog open and skip SecondaryButtonCommand.
Dependency property identifiers
Use these identifiers with WPF property APIs. The matching CLR properties appear above when the control exposes them.
CloseButtonCommandParameterProperty
public static readonly DependencyProperty CloseButtonCommandParameterProperty
Identifies the CloseButtonCommandParameter dependency property.
CloseButtonCommandProperty
public static readonly DependencyProperty CloseButtonCommandProperty
Identifies the CloseButtonCommand dependency property.
CloseButtonTextProperty
public static readonly DependencyProperty CloseButtonTextProperty
Identifies the CloseButtonText dependency property.
DefaultButtonProperty
public static readonly DependencyProperty DefaultButtonProperty
Identifies the DefaultButton dependency property.
IsPrimaryButtonEnabledProperty
public static readonly DependencyProperty IsPrimaryButtonEnabledProperty
Identifies the IsPrimaryButtonEnabled dependency property.
IsSecondaryButtonEnabledProperty
public static readonly DependencyProperty IsSecondaryButtonEnabledProperty
Identifies the IsSecondaryButtonEnabled dependency property.
PrimaryButtonCommandParameterProperty
public static readonly DependencyProperty PrimaryButtonCommandParameterProperty
Identifies the PrimaryButtonCommandParameter dependency property.
PrimaryButtonCommandProperty
public static readonly DependencyProperty PrimaryButtonCommandProperty
Identifies the PrimaryButtonCommand dependency property.
PrimaryButtonTextProperty
public static readonly DependencyProperty PrimaryButtonTextProperty
Identifies the PrimaryButtonText dependency property.
SecondaryButtonCommandParameterProperty
public static readonly DependencyProperty SecondaryButtonCommandParameterProperty
Identifies the SecondaryButtonCommandParameter dependency property.
SecondaryButtonCommandProperty
public static readonly DependencyProperty SecondaryButtonCommandProperty
Identifies the SecondaryButtonCommand dependency property.
SecondaryButtonTextProperty
public static readonly DependencyProperty SecondaryButtonTextProperty
Identifies the SecondaryButtonText dependency property.
TitleProperty
public static readonly DependencyProperty TitleProperty
Identifies the Title dependency property.
TitleTemplateProperty
public static readonly DependencyProperty TitleTemplateProperty
Identifies the TitleTemplate dependency property.