Home > OS >  C# WPF - What's this weird line that's showing up in Tooltip?
C# WPF - What's this weird line that's showing up in Tooltip?

Time:11-07

I styled my Tooltip using this lines of C# code:

Popup pp = new Popup();
ToolTipService.SetShowDuration(pp, 1000);
TextBlock tb = new TextBlock() { Text = errorMessage };
tb.Foreground = SystemColors.InfoTextBrush;
tb.Background = SystemColors.InfoBrush;
tb.TextWrapping = TextWrapping.Wrap;
tb.Padding = new Thickness(4, 0, 4, 0);
tb.TextAlignment = TextAlignment.Center;

Border b1 = new Border() { Child = tb };
pp.Child = b1;
b1.BorderThickness = new Thickness(1, 1, 1, 1);
b1.BorderBrush = SystemColors.ActiveBorderBrush;

pp.Height = 20;
pp.PlacementTarget = this;
pp.StaysOpen = false;

And when the Tooltip get rendered, it looks like this

enter image description here

Does anyone knows why's that line is showing? and how can I get rid of it?

CodePudding user response:

The rendering issue. Usually set UseLayoutRounding=true solves the issue.

TextBlock tb = new TextBlock() { Text = errorMessage,  UseLayoutRounding = true };

FrameworkElement.UseLayoutRounding

  • Related