A Customizable WPF TaskDialog
A WPF TaskDialog control written in C# that simulates the Vista TaskDialog

Introduction
This is an implementation of the Vista TaskDialog
for WPF.
MessageBox
By invoking one of the Show
method's static
overloads, the TaskDialog
acts as a replacement for the MessageBox
. It has four text properties: Header
, Content
, Detail
, and Footer
. Detail
is a collapsed region. The Header
and Footer
both have an icon property (HeaderIcon
, FooterIcon
, respectively), and the Header
has Background
and Foreground
properties.
// TaskDialog.Show method signature
public static TaskDialogResult Show(
string title,
string header,
string content,
string detail,
string footer,
TaskDialogButton button,
TaskDialogResult defaultResult,
TaskDialogIcon headerIcon,
TaskDialogIcon footerIcon,
Brush headerBackground,
Brush headerForeground)
// TaskDialog.Show method example
TaskDialog.Show("Task Dialog Options",
"The Header text for the message box",
"The Content text for the message box. this" +
" text will automatically wrap and is selectable.",
"The Detail text for the message box. this text " +
"will automatically wrap and is selectable",
"The Footer text for the message box.",
TaskDialogButton.Ok,
TaskDialogResult.None,
TaskDialogIcon.Information,
TaskDialogIcon.Shield,
Brushes.White,
Brushes.Navy);
Customizing the TaskDialog
Using the static Show
method, you are limited to only passing string
s to the Header
, Content
, Detail
, and Footer
properties.
To customize the dialog, you need to create an instance of the TaskDialog
class, set some properties, and call the Show
method.
// TaskDialog Instance example
TaskDialog dialog = new TaskDialog();
dialog.Title = "TaskDialog example";
dialog.HeaderIcon = TaskDialogIcon.Warning;
dialog.SystemSound = TaskDialogSound.Exclamation;
// header properties
dialog.Header = "This is the Header.";
dialog.HeaderBackground = Brushes.DarkGray;
dialog.HeaderForeground = Brushes.White;
// Content, Detail and Footer
dialog.Content = "This is the content";
dialog.Detail = "This is the detail";
dialog.Footer = "this is the Footer";
dialog.Show();
The TaskDialog
control derives from the HeaderedContentControl
class, which is where we get the Header
and Content
properties. Added to this are the Detail
and Footer
properties. These properties are of type object
and have their own template properties (HeaderTemplate
, ContentTemplate
, DetailTemplate
, and FooterTemplate
). The TaskDialog
has default data templates for text content which you can replace using the template properties above, so you can format text in any way you like. The following picture shows this by formatting the text with italics and underlines:
// DataTemplate for the content property above
<DataTemplate x:Key="_customContentDataTemplate">
<TextBlock Text="{Binding Content,
RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type Controls:TaskDialog}}}"
FontStyle="Italic"
TextDecorations="Underline"
TextWrapping="Wrap"/>
</DataTemplate>
Because the Header
, Content
, Detail
, and Footer
are of type object
, you are not limited to text, you can put anything you want on the TaskDialog
. Below is an example of the TaskDialog
looking like a Vista User Account Control prompt. The Content
property is a UserControl
which has an image and some text and two CommandButton
s (these are just normal buttons with a custom style and an added Header
property) which are included in the TaskDialog
.

A TaskDialog
simulating the Vista FileCopy window:

Additional Properties of Interest
This is a list of properties the TaskDialog
exposes (in alphabetical order):
Button1Text
: Typestring
. Sets the text of the button when theTaskDialogButton
property is set toCustom
Button2Text
: As aboveButton3Text
: As aboveDefaultResult
: TypeTaskDialogResult
. Sets the default buttonIsButton1Enabled
: Typebool
.Get
orset
theEnabled
state of the buttonIsButton2Enabled
: Same as aboveIsButton3Enabled
: Same as aboveIsCloseButtonEnabled
: Typebool
.Get
orset
theEnabled
state of the window close button (default isfalse
)IsExpanded
: Typebool
.Get
orset
the visibility of theDetail
sectionIsModal
: Typebool
.Get
orset
whether the dialog window is modalShowInTaskBar
: Typebool
.Get
orset
whether the dialog window displays in the taskbarSystemSound
: TypeTaskDialogSound
.Set
the system sound to play when the window is shownTaskDialogButton
: TypeTaskDialogButton
. The buttons to display on the window. Can beNone
,Ok
,OkCancel
,YesNo
,YesNoCancel
, orCustom
(see above for setting button captions)Title
: Typestring
. The window titleToggleButtonTexts
: This takes a class of typeTaskDialogToggleButtonTexts
which provides two properties for setting the text of the toggle button in its collapsed and expanded states (defaults to 'Show Details' and 'Hide Details').TopMost
: Set theZOrder
of the window
Demo
The download includes a project that demonstrates the TaskDialog
. Check out the button event handlers in Window1.xaml.cs to see how each TaskDialog
is created.
History
- 3rd November, 2008: Initial post
- 7th November, 2008: Updated source code
- 4th April, 2009: Updated source code
- 7th April, 2009: Updated source code