0

I have tried everything,

solution1: https://siderite.dev/blog/determining-if-textblock-has-been.html

solution2: http://blog.scottlogic.com/2011/01/31/automatically-showing-tooltips-on-a-trimmed-textblock-silverlight-wpf.html

My solution:

<TextBlock.ToolTip> 
    <MultiBinding Converter="{StaticResource ToolTipVisibilityWhenTextTrimmedConverter}">                                 
       <Binding ElementName="mytextblock" Path="Text"/>
       <Binding ElementName="mytextblock"/>
       <Binding ElementName="mytextblock" Path="MaxWidth"/>
    </MultiBinding>
</TextBlock.ToolTip>

and

public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
    var text = values[0];
    TextBlock tb = (TextBlock)values[1];
    var maxwidth = values[2];
    var result = CommonMethods.MeasureString(tb);
    bool isTextTrimmed = result.Width > (double)maxwidth;
    var retval = (isTextTrimmed) ? text : null;

    return retval;
}

But still when the TextBlock width is very close to get trimmed the ToolTip is shown. Sometimes when the last 2 characters are trimmed the ToolTip is not shown.

Any suggestions?

Siderite Zackwehdex
  • 6,293
  • 3
  • 30
  • 46
  • 1
    What's in your `CommonMethods.MeasureString`? – Szabolcs Dézsi Jan 11 '16 at 19:40
  • http://stackoverflow.com/questions/9264398/how-to-calculate-wpf-textblock-width-for-its-known-font-size-and-characters I use the formattedText to calculate the size the TextBlock's Text var formattedText = new FormattedText( candidate, CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, new Typeface(this.textBlock.FontFamily, this.textBlock.FontStyle, this.textBlock.FontWeight, this.textBlock.FontStretch), this.textBlock.FontSize, Brushes.Black); – George Sterg Jan 12 '16 at 08:52

0 Answers0