WPF,计算绘制一段文字需要多少宽度
private double GetTextWidth(string text)
{
var textBlock = new System.Windows.Controls.TextBlock { Text = text, TextWrapping = TextWrapping.NoWrap, FontSize = 14 };
textBlock.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
textBlock.Arrange(new Rect(textBlock.DesiredSize));
return textBlock.ActualWidth;
}