Click here to Skip to main content
13,868,293 members
Click here to Skip to main content
Add your own
alternative version


89 bookmarked
Posted 3 Nov 2008
Licenced CPOL

A Customizable WPF TaskDialog

, 8 Apr 2009
Rate this:
Please Sign up or sign in to vote.
A WPF TaskDialog control written in C# that simulates the Vista TaskDialog


This is an implementation of the Vista TaskDialog for WPF.


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.",

Customizing the TaskDialog

Using the static Show method, you are limited to only passing strings 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";


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}}}" 




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 CommandButtons (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: Type string. Sets the text of the button when the TaskDialogButton property is set to Custom
  • Button2Text: As above
  • Button3Text: As above
  • DefaultResult: Type TaskDialogResult. Sets the default button
  • IsButton1Enabled: Type bool. Get or set the Enabled state of the button
  • IsButton2Enabled: Same as above
  • IsButton3Enabled: Same as above
  • IsCloseButtonEnabled: Type bool. Get or set the Enabled state of the window close button (default is false)
  • IsExpanded: Type bool. Get or set the visibility of the Detail section
  • IsModal: Type bool. Get or set whether the dialog window is modal
  • ShowInTaskBar: Type bool. Get or set whether the dialog window displays in the taskbar
  • SystemSound: Type TaskDialogSound. Set the system sound to play when the window is shown
  • TaskDialogButton: Type TaskDialogButton. The buttons to display on the window. Can be None, Ok, OkCancel, YesNo, YesNoCancel, or Custom (see above for setting button captions)
  • Title: Type string. The window title
  • ToggleButtonTexts: This takes a class of type TaskDialogToggleButtonTexts 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 the ZOrder of the window


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.


  • 3rd November, 2008: Initial post
  • 7th November, 2008: Updated source code
  • 4th April, 2009: Updated source code
  • 7th April, 2009: Updated source code


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer
United Kingdom United Kingdom
No Biography provided

You may also be interested in...

Comments and Discussions

Questioni want only exception msg box so what is required files?? Pin
Member 105791221-Jun-15 22:33
memberMember 105791221-Jun-15 22:33 
QuestionMaking Show() static is MVVM unfriendly Pin
Dave Midgley13-Mar-12 7:45
memberDave Midgley13-Mar-12 7:45 
QuestionHide the show details when there is no details to show Pin
Sebastien Charest31-Jan-11 11:23
memberSebastien Charest31-Jan-11 11:23 
GeneralExtended WPF toolkit has now message box control. Pin
mammadkoma6-Nov-10 22:35
membermammadkoma6-Nov-10 22:35 
QuestionHow to get the DialogResult from UAC usercontrol Pin
-=barmaley=-20-Jan-10 10:31
member-=barmaley=-20-Jan-10 10:31 
GeneralProject reference problem Pin
Richard Deeming7-Apr-09 10:38
mveRichard Deeming7-Apr-09 10:38 
GeneralRe: Project reference problem Pin
alrh7-Apr-09 23:47
memberalrh7-Apr-09 23:47 
GeneralRe: Project reference problem Pin
Richard Deeming8-Apr-09 2:11
mveRichard Deeming8-Apr-09 2:11 
GeneralBug in OnButtonPreviewKeyDown Pin
Daniel Weck6-Apr-09 2:00
memberDaniel Weck6-Apr-09 2:00 
GeneralRe: Bug in OnButtonPreviewKeyDown Pin
alrh6-Apr-09 2:56
memberalrh6-Apr-09 2:56 
GeneralError in your code: Template PARTs Pin
Daniel Weck6-Apr-09 1:56
memberDaniel Weck6-Apr-09 1:56 
GeneralRe: Error in your code: Template PARTs Pin
Daniel Weck6-Apr-09 1:58
memberDaniel Weck6-Apr-09 1:58 
GeneralRe: Error in your code: Template PARTs Pin
alrh6-Apr-09 2:55
memberalrh6-Apr-09 2:55 
GeneralProposal for handling ESC key Pin
Daniel Weck6-Apr-09 0:21
memberDaniel Weck6-Apr-09 0:21 
GeneralRe: Proposal for handling ESC key Pin
alrh6-Apr-09 2:48
memberalrh6-Apr-09 2:48 
GeneralRe: Proposal for handling ESC key Pin
Daniel Weck6-Apr-09 9:50
memberDaniel Weck6-Apr-09 9:50 
GeneralRe: Proposal for handling ESC key Pin
alrh8-Apr-09 23:48
memberalrh8-Apr-09 23:48 
QuestionCenter Customizable WPF TaskDialog with its parent window [modified] Pin
Roberto Jucá3-Apr-09 12:26
memberRoberto Jucá3-Apr-09 12:26 
AnswerRe: Center Customizable WPF TaskDialog with its parent window Pin
alrh4-Apr-09 23:33
memberalrh4-Apr-09 23:33 
GeneralRe: Center Customizable WPF TaskDialog with its parent window [modified] Pin
Roberto Jucá5-Apr-09 9:00
memberRoberto Jucá5-Apr-09 9:00 
GeneralRe: Center Customizable WPF TaskDialog with its parent window Pin
alrh5-Apr-09 23:56
memberalrh5-Apr-09 23:56 
GeneralMulti-threaded version Pin
vic_ch200018-Jan-09 4:19
membervic_ch200018-Jan-09 4:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01 | 2.8.190214.1 | Last Updated 8 Apr 2009
Article Copyright 2008 by alrh
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid