我已经尝试了一切,
解决方案1:http://siderite.blogspot.com/2010/10/determining-if-textblock-has-been.html
我的解决方案:
<TextBlock.ToolTip>
<MultiBinding Converter="{StaticResource ToolTipVisibilityWhenTextTrimmedConverter}">
<Binding ElementName="mytextblock" Path="Text"/>
<Binding ElementName="mytextblock"/>
<Binding ElementName="mytextblock" Path="MaxWidth"/>
</MultiBinding>
</TextBlock.ToolTip>
和
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;
}
但是当TextBlock
宽度非常接近修剪时,显示ToolTip
。有时,当修剪最后2个字符时,ToolTip
不会显示。
有什么建议吗?