WPFTaskDialog.Core 1.0.0

dotnet add package WPFTaskDialog.Core --version 1.0.0
                    
NuGet\Install-Package WPFTaskDialog.Core -Version 1.0.0
                    
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="WPFTaskDialog.Core" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="WPFTaskDialog.Core" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="WPFTaskDialog.Core" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add WPFTaskDialog.Core --version 1.0.0
                    
#r "nuget: WPFTaskDialog.Core, 1.0.0"
                    
#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.
#:package WPFTaskDialog.Core@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=WPFTaskDialog.Core&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=WPFTaskDialog.Core&version=1.0.0
                    
Install as a Cake Tool

WPF Task Dialog Wrapper

Ported from the original .Net 4 version to .Net Core. No functional changes.

It is a drop-in assembly that lets you call up Task Dialogs in your WPF app. Uses the native TaskDialogIndirect API calls when available (Vista/7) and falls back to an emulated WPF dialog when not (XP and earlier).

Now available via NuGet! Search for "taskdialog" and give it a whirl!

Background

I've made very good use of Hedley Muscroft's WinForms emulator and wrapper for TaskDialogs in the past. In that same spirit, I've taken part of his hard work and done something very similar, but this time for WPF and .NET 4.0.

There are tons of other WPF/WinForms TaskDialog implementations out there, either those that wrap the Win32 APIs, or just providing a custom WPF dialog to use. A quick web search will find you plenty. What they don't give you is a unified way to use the native that still works on older Windows. I go into more detail on the rationale and history of all this in a blog post here.

Hedley's work is great and I've used it plenty of times, but I wanted something very similar that worked for WPF apps. I also thought I might take the time to try to improve on it, mostly thanks to the power of WPF and .NET 4.0.

Code

Add the reference to your WPF project. You'll find all of the classes under the TaskDialogInterop namespace. Use the TaskDialog class's static methods to show dialogs. Some work more akin to the more basic MessageBox, accepting a string and other parameters to customize the display. The real power, though, is found in the overload that takes a TaskDialogOptions object.

The basic flow in your apps will typically be something like this:

TaskDialogOptions config = new TaskDialogOptions();

config.Owner = this;
config.Title = "Task Dialog Title";
config.MainInstruction = "The main instruction text for the TaskDialog goes here";
config.Content = "The content text for the task dialog is shown " + 
             "here and the text will automatically wrap as needed.";
config.ExpandedInfo = "Any expanded content text for the " + 
                  "task dialog is shown here and the text " + 
                  "will automatically wrap as needed.";
config.VerificationText = "Don't show me this message again";
config.CustomButtons = new string[] { "&Save", "Do&n't save", "&Cancel" };
config.MainIcon = VistaTaskDialogIcon.Shield;
config.FooterText = "Optional footer text with an icon can be included.";
config.FooterIcon = VistaTaskDialogIcon.Warning;

TaskDialogResult res = TaskDialog.Show(config);

The options object lets you specify all of the particulars. Anything you don't define will be ignored or unused. This makes it very easy to display as much or as little as you need to.

As you can see, buttons are handled via simple string arrays. Each string in the array will be converted to a button using the given label. Use the ampersand character (&) before a letter to denote the accelerator.

Depending on the method you use, you'll either get back a TaskDialogSimpleResult or a TaskDialogResult. The simple one works just like the DialogResult you're probably used to. In fact, it can be cast successfully back and forth between the two. This is nice if you have existing services/code that expect a DialogResult. The full result object contains everything you'd want to know about how the user acted on your dialog. It has properties you can read to find out which button, command link, radio, etc. was chosen/clicked.

You can read more as well as see screenshots here.

Details

  • Project ported to Visual Studio 2019 (created in Visual Studio 2010 originally)
  • .Net Core 3.1
  • Uses the native TaskDialogIndirect API when available (Vista/7)
  • Licensed under The Code Project Open License (CPOL) 1.02
    • Can be freely redistributed
    • Can be modified
    • Can be used in commercial software
    • No warranty/guarantee
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.0 12,699 8/20/2020

1.0.0: Ported original version to .Net Core 3.1 (refactored code, no public renaming or any breaking changes)