XTaskDialog 1.0.2

dotnet add package XTaskDialog --version 1.0.2
NuGet\Install-Package XTaskDialog -Version 1.0.2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="XTaskDialog" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add XTaskDialog --version 1.0.2
#r "nuget: XTaskDialog, 1.0.2"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install XTaskDialog as a Cake Addin
#addin nuget:?package=XTaskDialog&version=1.0.2

// Install XTaskDialog as a Cake Tool
#tool nuget:?package=XTaskDialog&version=1.0.2

XTaskDialog

A .NET library that wraps the Win32 Task Dialog API.

Message Box

For a simple message box use the static method TaskDialog.Show:

TaskDialogResult result = TaskDialog.Show(parent, "Main Instruction", "Content",
                                            TaskDialogButton.Yes|TaskDialogButton.No);
if (result == TaskDialogResult.Yes)
{
    // ....
}

Simple Message Box

For more advanced usages, such as displaying a footer, verification check box, etc... Construct an instance of TaskDialog and set its properties:

TaskDialog dlg = new TaskDialog(parent, "Main Instruction", "Content");
dlg.VerificationText = "Verification Text";
dlg.FooterText = "Footer Text";
dlg.FooterIcon = TaskDialogIcon.Information;
dlg.Buttons = TaskDialogButton.None;
dlg.CustomButtons = new TaskDialogCustomButton[]
{
    new TaskDialogCustomButton((int)TaskDialogResult.Yes, "Okay"),
    new TaskDialogCustomButton((int)TaskDialogResult.No, "No way"),
    new TaskDialogCustomButton(101, "Later")
};

TaskDialogResult result = dlg.Show(out bool verificationChecked);
if (result == TaskDialogResult.Yes)
{
    // ...
}

Advanced Message Box

Progress Dialog

When the progress dialog is passed a System.Threading.Tasks.Task it will be displayed until the task is complete, throws an exception or is canceled. It supports both Task and Task<T>.

If you can provide a method that creates the task then its as simple as:

try
{
    // ProgressDialog.Show will pass a CancellationToken and a progress object to the delegate
    int result = ProgressDialog.Show((c, p) => MyMethodAsync(c, p), parent, "Main Instruction", "Content");
    
    // Do something with result...
}
catch (OperationCanceledException)
{
    // The user clicked the cancel button
}
catch (Exeception e)
{
    // The task threw an exception
}

// Dummy async method
private async Task<int> MyMethodAsync(CancellationToken cancellation, IProgress<ProgressDialogProgressInfo> progress)
{
    for (int i = 0; i < 10; i++)
    {
        cancellation.ThrowIfCancellationRequested();

        progress.Report(new ProgressDialogProgressInfo()
        {
            Content = $"step {i}",
        });

        await Task.Delay(1000);
    }

    return 123;
}

Progress Dialog

To display a progres dialog for an already running task or existing cancellation token do:

// Create the cancellation token (optional)
using (CancellationTokenSource cts = new CancellationTokenSource())
{
    // Create the progress info (optional)
    ProgressDialogProgressInfo progressInfo = new ProgressDialogProgressInfo();

    // Start the task
    Task<int> task = TestAsync(cts.Token, new Progress<ProgressDialogProgressInfo>(p => progressInfo.SetFrom(p)));

    try
    {
        // Display the progress dialog - it wont display if the task is already complete
        int result = ProgressDialog.Show(task, parent, "Main Instruction", "Content", cts, progressInfo);

        // Do something with result...
    }
    catch (OperationCanceledException)
    {
        // The user clicked the cancel button
    }
    catch (Exeception e)
    {
        // The task threw an exception
    }
}

Notes about WPF and the parent window

The methods can take the HWND of the parent window as an IntPtr. If you pass IntPtr.Zero the message/progress dialog will have no parent (meaning that it will go behind your window).

In WPF you can obtain the HWND for a window using the System.Windows.Interop.WindowInteropHelper class, such as:

// Get the HWND of the WPF window
WindowInteropHelper helper = new WindowInteropHelper(myWpfWindow);

// Display a message box where its parent will be the WPF window
TaskDialog.Show(helper.Handle, "Main Instruction", "Content");
Product Compatible and additional computed target framework versions.
.NET net6.0-windows7.0 is compatible.  net7.0-windows was computed.  net7.0-windows7.0 is compatible.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0-windows7.0

    • No dependencies.
  • net7.0-windows7.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.2 141 6/13/2023
1.0.1 120 6/13/2023