我正在尝试在 WPF 中的 TextBlock 上设置 FontStretch 属性,但似乎不起作用。我尝试了 Expanded、Condensed 等,但文本外观没有改变。
我正在使用 Framework 4.0 的 Windows XP 上工作,并使用 Verdana 和 Arial 进行了测试。
它仅适用于 Windows 7 还是仅适用于某些特定字体?
编辑:如果它不适用于所有字体,是否有支持此功能的字体列表?或者是否可以修改像 Verdana/Arial 这样的字体来支持它?
最佳答案
要在不支持 FontStretch 的字体中获得与 FontStretch 类似的效果,您可以在 TextBlock 上使用 LayoutTransform:
<Application.Resources>
<ScaleTransform x:Key="FontStretchCondensed" ScaleX="0.8" />
<ScaleTransform x:Key="FontStretchExpanded" ScaleX="1.2" />
</Application.Resources>
...
<TextBlock Text="This is my text"
LayoutTransform="{StaticResource FontStretchCondensed}" />
如果您希望 TextBlock 中的所有文本都显示为压缩形式,也可以在样式中进行设置:
<Style TargetType="TextBlock">
<Style.Setters>
<Setter Property="LayoutTransform" Value="{StaticResource FontStretchCondensed}" />
</Style.Setters>
</Style>
关于.net - 为什么 FontStretch 在 WPF 中不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2948290/