Vertical space in command links in TaskDialog since version 1.1

I noticed a large vertical space in the dialog box of my task (a space between the names of commands and instructions), which look very bad. It began to appear immediately after updating WindowsAPICodePack to version 1.1.

Here is the code:

TaskDialog td = new TaskDialog(); var b1 = new TaskDialogCommandLink("b1", "foo", "bar"); var b2 = new TaskDialogCommandLink("b2", "one", "two"); td.Controls.Add(b1); td.Controls.Add(b2); td.Caption = "Caption"; td.InstructionText = "InstructionText"; td.Text = "Text"; td.Show(); 

Here is the result:

Ugly task dialog with vertical space in command links

Formerly, "bar" will appear right below "foo", but now it looks as if there is an empty line between them. Is this a problem at my end (and does anyone know what it could be), or are you guys experiencing this too?

+4
source share
2 answers

I have the same error in version 1.1. This seems to be related to the TaskDialogCommandLink class toString string.Format with Environment.NewLine , which does not display cleanly when passed to TaskDialog itself.

 public override string ToString() { return string.Format(CultureInfo.CurrentCulture, "{0}{1}{2}", Text ?? string.Empty, (!string.IsNullOrEmpty(Text) && !string.IsNullOrEmpty(instruction)) ? Environment.NewLine : string.Empty, instruction ?? string.Empty); } 

In any case, I use an implementation subclass to simplify the arguments and overload the method to pass a line containing a simple "\ n", although I do not need to internationalize my application, and so I can do something a little easier.

 public override string ToString() { string str; bool noLabel = string.IsNullOrEmpty(this.Text); bool noInstruction = string.IsNullOrEmpty(this.Instruction); if (noLabel & noInstruction) { str = string.Empty; } else if (!noLabel & noInstruction) { str = this.Text; } else if (noLabel & !noInstruction) { str = base.Instruction; } else { str = this.Text + "\n" + this.Instruction; } return str; } 
+5
source

I noticed the same problems with the Code Pack v1.1 API on Windows 8. DougM is correct, overriding ToString() will solve the problem.

Here is the updated version, just drop this class into your project and use TaskDialogCommandLink instead of TaskDialogCommandLinkEx .

 using Microsoft.WindowsAPICodePack.Dialogs; internal class TaskDialogCommandLinkEx : TaskDialogCommandLink { public override string ToString() { string str; var noLabel = string.IsNullOrEmpty(Text); var noInstruction = string.IsNullOrEmpty(Instruction); if (noLabel & noInstruction) { str = string.Empty; } else if (!noLabel & noInstruction) { str = Text; } else if (noLabel & !noInstruction) { str = Instruction; } else { str = Text + "\n" + Instruction; } return str; } } 
+2
source

Source: https://habr.com/ru/post/1492018/


All Articles