【发布时间】:2011-04-07 09:43:43
【问题描述】:
我正在尝试根据可用空间动态缩短标签。我使用 FormattedText 来确定候选字符串的长度
formattedText = new FormattedText(candidateString, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, typeface, FontSize = fontSize, Brushes.Black);
我应该能够从包含文本的标签中检索字体;但是我一直遇到障碍:
- 标签包含 FontFamily 但不包含字体。
- 我无法从 FontFamily 创建新字体,因为我无法获得单个 FontFamily 名称
Typeface t = new Typeface(theLabel.FontFamily.FamilyNames.?, theLabel.FontStyle, theLabel.FontSize, theLabel.FontStretch);
这看起来应该很简单:我想要那个标签中使用的字体(指向屏幕)。如何创建用于测量字符串长度的字体?有没有更简单的方法来实现这一点?我在这里错过了什么?
谢谢。
【问题讨论】:
-
您是否考虑过使用 TextBlock 和 TextTrimming 属性?
标签: wpf label font-family