Windows API Code Pack TaskDialog missing icon
Asked Answered
B

2

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>
Bioplasm answered 21/3, 2014 at 14:29 Comment(0)
B
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;
}
Bioplasm answered 22/3, 2014 at 11:0 Comment(8)
how to do the same in vb.net?Bertrando
AddHandler taskDialog.Opened, Sub(sender As TaskDialog, args As EventArgs) sender.Icon = sender.Icon sender.InstructionText = sender.InstructionText End SubRouth
Download WindowsAPICodePack by Aybe from NuGet to solve this issue. Works for me!Bainter
The FooterIcon line will only work, if the FooterText is set to something other than null or an empty string. +@csrowellVictorinavictorine
@Bainter I wish you put the link in your comment.Vd
This solution throws AccessViolationExceptionVd
The solution for this is to use WindowsAPICodePack by AybeVd
I have to add, you seem to need to install v1.1.2 for this fix, which is unfortunately kinda buggy.Bainter
G
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.

Governess answered 5/8, 2016 at 15:57 Comment(2)
Try if (Icon != TaskDialogStandardIcon.None) Icon = Icon; if (FooterIcon != TaskDialogStandardIcon.None) FooterIcon = FooterIcon;.Bainter
PS: If you have trouble with the right dialog window height, add then: if (InstructionText != null) InstructionText = InstructionText;. Hope that helped.Bainter

© 2022 - 2024 — McMap. All rights reserved.