I have tried everything,
solution1: https://siderite.dev/blog/determining-if-textblock-has-been.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?