/// <summary>
/// 判断文本框内容是否超出容器范围
/// </summary>
/// <param name="textBlock">需要判断的文本框控件</param>
/// <returns></returns>
public bool IsTextTrimmed(TextBlock textBlock)
{
Typeface typeface = new Typeface(
textBlock.FontFamily,
textBlock.FontStyle,
textBlock.FontWeight,
textBlock.FontStretch);
FormattedText formattedText = new FormattedText(
textBlock.Text,
System.Threading.Thread.CurrentThread.CurrentCulture,
textBlock.FlowDirection,
typeface,
textBlock.FontSize,
textBlock.Foreground);
formattedText.MaxTextWidth = textBlock.ActualWidth;
bool isTrimmed = formattedText.Height > textBlock.ActualHeight ||
formattedText.Width > formattedText.MaxTextWidth;
return isTrimmed;
}