神不在的星期二
使用FormattedText该类。我在代码中做了一个辅助函数:private Size MeasureString(string candidate){ var formattedText = new FormattedText( candidate, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface(this.textBlock.FontFamily, this.textBlock.FontStyle, this.textBlock.FontWeight, this.textBlock.FontStretch), this.textBlock.FontSize, Brushes.Black, new NumberSubstitution(), 1); return new Size(formattedText.Width, formattedText.Height);}它返回可在WPF布局中使用的与设备无关的像素。