15.02.2015 Views

C# 4 and .NET 4

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

1410 ❘ aPPendiX Guidelines fOr windOws 7 And windOws server 2008 r2<br />

The public class from the Windows API Code Pack used to show<br />

task dialogs is TaskDialog. To display a simple dialog, only the<br />

static method Show() must be invoked. The simple dialog is shown<br />

in Figure A-9.<br />

TaskDialog.Show("Simple Task Dialog",<br />

"Additional Information", "Title");<br />

figure a-9<br />

code snippet TaskDialogDemo/MainWindow.xaml.cs<br />

For more features of the TaskDialog class, you can set the<br />

Caption, Text, St<strong>and</strong>ardButtons, <strong>and</strong> MainIcon properties.<br />

You can see the result in Figure A-10.<br />

var dlg1 = new TaskDialog();<br />

dlg1.Caption = "Title";<br />

dlg1.Text = "Some Information";<br />

dlg1.St<strong>and</strong>ardButtons =<br />

figure a-10<br />

TaskDialogSt<strong>and</strong>ardButtons.Ok |<br />

TaskDialogSt<strong>and</strong>ardButtons.Cancel;<br />

dlg1.Icon = TaskDialogSt<strong>and</strong>ardIcon.Information;<br />

dlg1.Show();<br />

With the task dialog, you can set the shield icon that was<br />

first shown with comm<strong>and</strong> links. Also, you can exp<strong>and</strong> it by<br />

setting the ExpansionMode property. With the enumeration<br />

TaskDialogExp<strong>and</strong>edInformationLocation, you can specify<br />

that either the content or the footer should be exp<strong>and</strong>ed.<br />

Figure A-11 shows the task dialog in collapsed mode.<br />

var dlg2 = new TaskDialog();<br />

dlg2.Caption = "Title";<br />

figure a-11<br />

dlg2.Text = "Some Information";<br />

dlg2.St<strong>and</strong>ardButtons = TaskDialogSt<strong>and</strong>ardButtons.Yes |<br />

TaskDialogSt<strong>and</strong>ardButtons.No;<br />

dlg2.Icon = TaskDialogSt<strong>and</strong>ardIcon.Shield;<br />

dlg2.DetailsExp<strong>and</strong>edText = "Additional Text";<br />

dlg2.DetailsExp<strong>and</strong>edLabel = "Less Information";<br />

dlg2.DetailsCollapsedLabel = "More Information";<br />

dlg2.ExpansionMode = TaskDialogExp<strong>and</strong>edDetailsLocation.Exp<strong>and</strong>Content;<br />

dlg2.FooterText = "Footer Information";<br />

dlg2.FooterIcon = TaskDialogSt<strong>and</strong>ardIcon.Information;<br />

dlg2.Show();<br />

A task dialog can also contain other controls. In the<br />

following code snippet, a task dialog is created that contains<br />

two radio buttons, a comm<strong>and</strong> link, <strong>and</strong> a progress control.<br />

You’ve already seen comm<strong>and</strong> links in the previous section,<br />

<strong>and</strong> indeed, comm<strong>and</strong> links are used very frequently within<br />

task dialogs. Figure A-12 shows the task dialog with the<br />

controls in the content area. Of course, you can also combine<br />

the expansion mode with controls.<br />

var radio1 = new TaskDialogRadioButton();<br />

radio1.Name = "radio1";<br />

radio1.Text = "One";<br />

var radio2 = new TaskDialogRadioButton();<br />

radio2.Name = "radio2";<br />

radio2.Text = "Two";<br />

figure a-12<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!