3

The icons in my TaskDialog are missing:

And in the taskbar:

My code is this:

using Microsoft.WindowsAPICodePack;
using Microsoft.WindowsAPICodePack.Dialogs;

...

TaskDialog taskDialog = new TaskDialog();
taskDialog.Caption = "Error";
taskDialog.InstructionText = "Test error message.";
taskDialog.Text = "Icon seems to be missing.";
taskDialog.DetailsExpandedText = "Test";
taskDialog.DetailsCollapsedLabel = "Expand";
taskDialog.StandardButtons = TaskDialogStandardButtons.Ok;
taskDialog.Icon = TaskDialogStandardIcon.Error;
taskDialog.Show();

I'm using version 1.1 from here. Any clue why they are missing and how to enable them? Dependencies are set as following:

  <dependency>
    <dependentAssembly>
      <assemblyIdentity
      type="win32"
      name="Microsoft.Windows.Common-Controls"
      version="6.0.0.0"
      processorArchitecture="*"
      publicKeyToken="6595b64144ccf1df"
      language="*"
/>
    </dependentAssembly>
  </dependency>
jacobz
  • 3,191
  • 12
  • 37
  • 61

2 Answers2

9

I've found a workaround to this. Apparently it is a bug in the API itself.

taskDialog.Opened += new EventHandler(taskDialog_Opened);

...

public void taskDialog_Opened(object sender, EventArgs e)
{
    TaskDialog taskDialog = sender as TaskDialog;
    taskDialog.Icon = taskDialog.Icon;
    taskDialog.FooterIcon = taskDialog.FooterIcon;
    taskDialog.InstructionText = taskDialog.InstructionText;
}
jacobz
  • 3,191
  • 12
  • 37
  • 61
  • how to do the same in vb.net? – Arie Oct 18 '15 at 10:35
  • `AddHandler taskDialog.Opened, Sub(sender As TaskDialog, args As EventArgs) sender.Icon = sender.Icon sender.InstructionText = sender.InstructionText End Sub` – Velcro Apr 24 '16 at 13:58
  • Download WindowsAPICodePack by Aybe from NuGet to solve this issue. Works for me! – KnorxThieus Aug 18 '16 at 10:53
  • The `FooterIcon` line will only work, if the FooterText is set to something other than `null` or an empty string. +@csrowell – Adam L. S. Jun 02 '17 at 16:01
  • 1
    @KnorxThieus I wish you put the link in your comment. – Rich Aug 03 '17 at 00:54
  • This solution throws AccessViolationException – Rich Aug 03 '17 at 01:42
  • 2
    The solution for this is to use [WindowsAPICodePack](https://github.com/aybe/Windows-API-Code-Pack-1.1?utm_source=recordnotfound.com) by Aybe – Rich Aug 03 '17 at 01:43
  • I have to add, you seem to need to install v1.1.2 for this fix, which is [unfortunately kinda buggy](https://github.com/aybe/Windows-API-Code-Pack-1.1/issues/41). – KnorxThieus Aug 25 '17 at 19:46
0

I'd add this as a comment but I don't have enough rep. The marked answer worked for me once I removed this line of code:

    taskDialog.FooterIcon = taskDialog.FooterIcon;

It was causing an unhandled exception.

csrowell
  • 912
  • 9
  • 18
  • Try `if (Icon != TaskDialogStandardIcon.None) Icon = Icon; if (FooterIcon != TaskDialogStandardIcon.None) FooterIcon = FooterIcon;`. – KnorxThieus Aug 28 '17 at 20:17
  • **PS:** If you have trouble with the right dialog window height, add then: `if (InstructionText != null) InstructionText = InstructionText;`. Hope that helped. – KnorxThieus Aug 30 '17 at 11:28