Table of Contents

Class ContentDialogHost

Namespace
Wpf.Ui.Controls
Assembly
Wpf.Ui.dll

Provides a host control for displaying modal content dialogs within a WPF window. Ensures that only one dialog host is registered per window and manages dialog presentation and interaction blocking as needed.

public class ContentDialogHost : ContentControl, IAnimatable, ISupportInitialize, IFrameworkInputElement, IInputElement, IQueryAmbient, IAddChild
Inheritance
ContentDialogHost
Implements
Inherited Members

Examples

XAML (place near the root of the Window):

<Window x:Class="MyApp.MainWindow" xmlns:ui="clr-namespace:Wpf.Ui.Controls;assembly=Wpf.Ui">
  <Grid>
    <ui:ContentDialogHost x:Name="RootDialogHost" />
  </Grid>
</Window>

C# (showing a simple dialog via the host):

var dialog = new ContentDialog(RootDialogHost)
{
    Title = "Confirm",
    Content = "Are you sure?",
    PrimaryButtonText = "Yes",
    CloseButtonText = "No",
};

var result = await dialog.ShowAsync();

Remarks

Use this control to present modal dialogs that overlay application content and optionally disable interaction with sibling elements.

Placement Requirements: 1. Place near the root of the window's visual tree to ensure broad coverage. 2. Position as the last sibling among its peers to guarantee the highest Z-order.

Only one instance of ContentDialogHost can be registered per Window; attempting to register multiple instances will result in an exception. To retrieve the dialog host associated with a specific window, use GetForWindow(Window?).

Constructors

ContentDialogHost()

Initializes a new instance of the ContentDialogHost class.

public ContentDialogHost()

Fields

IsDisableSiblingsEnabledProperty

Identifies the IsDisableSiblingsEnabled dependency property.

public static readonly DependencyProperty IsDisableSiblingsEnabledProperty

Field Value

DependencyProperty

Properties

IsDisableSiblingsEnabled

Gets or sets a value indicating whether sibling elements of the dialog host should be disabled while the dialog is displayed. The default value is false.

public bool IsDisableSiblingsEnabled { get; set; }

Property Value

bool

true to disable sibling elements; false to leave sibling elements unaffected.

Remarks

When enabled, sibling elements in the host window may appear disabled while the ContentDialog is displayed. This option is disabled by default and is intended for scenarios where background interaction must be prevented.

Methods

GetForWindow(Window?)

Returns the ContentDialogHost instance registered for the specified Window, if any.

public static ContentDialogHost? GetForWindow(Window? window)

Parameters

window Window

Window to query for a registered ContentDialogHost.

Returns

ContentDialogHost

The registered ContentDialogHost for the given window, or null if none is registered.

Examples

var host = ContentDialogHost.GetForWindow(Window.GetWindow(someElement));

OnContentChanged(object?, object?)

Called when the Content property changes.

protected override void OnContentChanged(object? oldContent, object? newContent)

Parameters

oldContent object

The old value of the Content property.

newContent object

The new value of the Content property.