【发布时间】:2011-06-21 11:33:39
【问题描述】:
在 WPF 中有 System.Windows.Media 命名空间 MSDN FormattedText 中的 FormattedText,我可以这样使用:
private static Size GetTextSize(string txt, string font, int size, bool isBold)
{
Typeface tf = new Typeface(new System.Windows.Media.FontFamily(font),
FontStyles.Normal,
(isBold) ? FontWeights.Bold : FontWeights.Normal,
FontStretches.Normal);
FormattedText ft = new FormattedText(txt, new CultureInfo("en-us"), System.Windows.FlowDirection.LeftToRight, tf, (double)size, System.Windows.Media.Brushes.Black, null, TextFormattingMode.Display);
return new Size { Width = ft.WidthIncludingTrailingWhitespace, Height = ft.Height };
}
除了调用服务器之外,Silverlight 中是否有一种以像素为单位获取宽度的好方法(目前高度并不重要)?
【问题讨论】:
标签: text silverlight-4.0 fontmetrics