Table of Contents

Class ContentDialogService

Namespace
Wpf.Ui
Assembly
Wpf.Ui.dll

Represents a contract with the service that creates ContentDialog.

public class ContentDialogService : IContentDialogService
Inheritance
ContentDialogService
Implements
Inherited Members
Extension Methods

Examples

<ContentDialogHost x:Name="RootContentDialogPresenter" Grid.Row="0" />
IContentDialogService contentDialogService = new ContentDialogService();
contentDialogService.SetContentPresenter(RootContentDialogPresenter);

await _contentDialogService.ShowAsync(
    new ContentDialog(){
        Title = "The cake?",
        Content = "IS A LIE!",
        PrimaryButtonText = "Save",
        SecondaryButtonText = "Don't Save",
        CloseButtonText = "Cancel"
    }
);

Methods

GetContentPresenter()

[Obsolete("Use GetDialogHost instead.")]
public ContentPresenter? GetContentPresenter()

Returns

ContentPresenter

GetDialogHost()

Provides direct access to the ContentPresenter

[Obsolete("Use GetDialogHostEx() instead.")]
public ContentPresenter? GetDialogHost()

Returns

ContentPresenter

Reference to the currently selected ContentPresenter which displays the ContentDialog's.

Remarks

DEPRECATED: This method is obsolete. Use GetDialogHostEx() instead.

GetDialogHostEx()

Gets the ContentDialogHost currently associated with the content.

public ContentDialogHost? GetDialogHostEx()

Returns

ContentDialogHost

The associated ContentDialogHost instance, or null if no dialog host is currently assigned.

SetContentPresenter(ContentPresenter)

[Obsolete("Use SetDialogHost instead.")]
public void SetContentPresenter(ContentPresenter contentPresenter)

Parameters

contentPresenter ContentPresenter

SetDialogHost(ContentPresenter)

[Obsolete("Use SetDialogHost(ContentDialogHost) instead.")]
public void SetDialogHost(ContentPresenter contentPresenter)

Parameters

contentPresenter ContentPresenter

Remarks

DEPRECATED: This method is obsolete. Use SetDialogHost(ContentDialogHost) instead.

SetDialogHost(ContentDialogHost)

Sets the ContentDialogHost that will host and present content dialogs.

public void SetDialogHost(ContentDialogHost dialogHost)

Parameters

dialogHost ContentDialogHost

The ContentDialogHost instance to use for dialog presentation.

Remarks

This method sets the enhanced ContentDialogHost to contain and manage dialogs. For compatibility reasons, an instance can have either a legacy host (set via SetDialogHost(ContentPresenter)) or an enhanced host (set via this method), but not both.

Exceptions

ArgumentNullException

Thrown when dialogHost is null.

InvalidOperationException

Thrown when a legacy dialog host (ContentPresenter) has already been set via SetDialogHost(ContentPresenter). Only one host type can be set per instance.

ShowAsync(ContentDialog, CancellationToken)

Asynchronously shows the specified dialog.

public Task<ContentDialogResult> ShowAsync(ContentDialog dialog, CancellationToken cancellationToken)

Parameters

dialog ContentDialog

The dialog to be displayed.

cancellationToken CancellationToken

A cancellation token that can be used to cancel the operation.

Returns

Task<ContentDialogResult>

A task that represents the asynchronous operation. The task result contains the dialog result.