将 FontWeight 设置为 Bold 会缩小文本大小 [英] Setting FontWeight to Bold shrinks text size

查看:30
本文介绍了将 FontWeight 设置为 Bold 会缩小文本大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在设置一个资源字典来为我的 WPF 应用程序中的所有控件设置样式,并且在设置标签的字体粗细时我发现了一些奇怪的行为.

I've been setting up a resource dictionary to style all the controls in my WPF application and I've discovered some odd behaviour when setting the font weight for a label.

我必须为标签设置样式,第一个使用正常字体粗细:

I have to styles set up for labels, the first with normal font weight :

<Style x:Key="Label" TargetType="{x:Type Label}">
    <Setter Property="VerticalAlignment" Value="Center"/>
    <Setter Property="Margin" Value="10,0"/>
</Style>

第二个设置为粗体:

<Style x:Key="LabelBold" TargetType="{x:Type Label}">
    <Setter Property="VerticalAlignment" Value="Center"/>
    <Setter Property="Margin" Value="10,0"/>
    <Setter Property="FontWeight" Value="Bold"/>
</Style>

问题是,当我使用粗体加权字体时,文本会缩小(或文本间距):

The trouble is that when I use the bold weighted font, the text shrinks (or the text spacing) :

我已经搜索过,但似乎找不到任何原因,如果有的话,我希望文本会因字母粗细增加而扩展.这是注定要发生的吗?如果是,有没有办法解决?

I've searched about but I can't seem to see any reason for this, if anything I'd expect the text to expand because of the letter thickness increasing. Is this meant to happen and if so is there a way around it?

该窗口使用以下字体:

<Setter Property="TextOptions.TextFormattingMode" Value="Display"/>
<Setter Property="FontFamily" Value="Calibri"/>
<Setter Property="FontSize" Value="12"/>

推荐答案

根据 Mark Hall 和 Sayed Saad 的评论进行一些调查后,我设法找出导致此问题的原因:TextOptions.TextFormattingMode = Display.

After a bit of investigation following on from Mark Hall and Sayed Saad's comments I managed to work out what was causing this: TextOptions.TextFormattingMode = Display.

正如 Mark 指出的那样,当您增大字体大小时,粗体文本确实会比普通字体文本大.但是,如果我将 TextFormattingMode 更改为理想",那么无论字体大小如何,粗体都会比普通字体大.

As Mark pointed out, the bold font text does get bigger than the normal font text when you up the font size. However, if I changed the TextFormattingMode to "Ideal" then the bold font is bigger than the normal font irrespective of the font size.

根据我在此处的发现,我发布了另一个问题,可以在此处找到答案:TextOptions.TextFormattingMode 影响具有粗体粗细的文本

Based on my findings here I posted another question, the answer to this can be found here: TextOptions.TextFormattingMode affecting text with bold font weight

这篇关于将 FontWeight 设置为 Bold 会缩小文本大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆