Windows API Code Pack TaskDialog missing icon

丶灬走出姿态 提交于 2019-12-04 04:13:39

问题


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>

回答1:


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;
}



回答2:


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.



来源:https://stackoverflow.com/questions/22561584/windows-api-code-pack-taskdialog-missing-icon

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!