From f3920e100dd4da6c815d31c0f0b0cae736af2882 Mon Sep 17 00:00:00 2001 From: S T Chan Date: Tue, 7 Jan 2014 13:14:20 -0500 Subject: [PATCH] added TaskDialogPresenter.cs --- PdfScribeCore/TaskDialogPresenter.cs | 54 ++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 PdfScribeCore/TaskDialogPresenter.cs diff --git a/PdfScribeCore/TaskDialogPresenter.cs b/PdfScribeCore/TaskDialogPresenter.cs new file mode 100644 index 0000000..3d6d5e6 --- /dev/null +++ b/PdfScribeCore/TaskDialogPresenter.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Windows; + +using APICodePack = Microsoft.WindowsAPICodePack.Dialogs; + +namespace PdfScribeCore +{ + abstract class TaskDialogPresenter + { + + protected abstract APICodePack.TaskDialogStandardIcon DefaultTaskIcon { get; } // Override this to set the dialog icon you want + + /// + /// Pops up a simple TaskDialog box + /// with just a Close button and + /// the default standard dialog icon + /// + /// Text that goes in the window's caption + /// Instructional text (Appears next to the error icon) + /// Smaller message detail text at bottom + public virtual void ShowSimple(String captionText, + String instructionText, + String messageText) + { + using (APICodePack.TaskDialog simpleTaskDialog = new APICodePack.TaskDialog()) + { + simpleTaskDialog.Caption = captionText; + simpleTaskDialog.InstructionText = instructionText; + simpleTaskDialog.Text = messageText; + simpleTaskDialog.Icon = this.DefaultTaskIcon; + simpleTaskDialog.StandardButtons = APICodePack.TaskDialogStandardButtons.Close; + simpleTaskDialog.Opened += new EventHandler(simpleTaskDialog_Opened); + simpleTaskDialog.Show(); + } + } + + private void simpleTaskDialog_Opened(object sender, EventArgs e) + { + // Really fucking annoying - + // There's a bug somewhere in the API Code Pack that + // causes the icon not to show + // unless you set it on the Opened event + // See: http://stackoverflow.com/questions/15645592/taskdialogstandardicon-not-working-on-task-dialog + // One of these days I'll try to find and fix it (honestly I hope + // someone else fixes first - also why isn't the API Code pack on codeplex + // or github so people can push patches), but until then... + ((APICodePack.TaskDialog)sender).Icon = this.DefaultTaskIcon; + } + + } +}