The following textblock wraps and trims as expected. The elipsis \"...\" is displayed when the text is trimmed.
The solution above didn't work for me if the TextBlock is part of a ListBoxItem DataTemplate. I propose another solution:
public class MyTextBlock : System.Windows.Controls.TextBlock
{
protected override void OnToolTipOpening(WinControls.ToolTipEventArgs e)
{
if (TextTrimming != TextTrimming.None)
{
e.Handled = !IsTextTrimmed();
}
}
private bool IsTextTrimmed()
{
Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
return ActualWidth < DesiredSize.Width;
}
}
XAML: