Giter Club home page Giter Club logo

wpf-task-dialog's Introduction

WPF Task Dialog Wrapper

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 created in Visual Studio 2010
  • .NET 4.0 Client Profile
  • 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

wpf-task-dialog's People

Contributors

yadyn avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.