Style 中设置的 FontSize 与 Blend 中的 FontSize 不匹配

发布于 2024-12-27 00:33:30 字数 814 浏览 6 评论 0原文

我在网格中有一个标签,并从资源字典中应用了样式。除其他事项外,样式将标签的 FontSize 属性更改为 14。

    <Style x:Key="lblForm" TargetType= "{x:Type Label}">
    <Setter Property="FontSize" Value="14"/>
    <Setter Property="Foreground" Value="Black"/>
    <Setter Property="HorizontalAlignment" Value="Right"/>
    <Setter Property="VerticalAlignment" Value="Center"/>
    <Setter Property="Margin" Value="0,0,6,0"/>
</Style>

我按以下方式将样式应用到标签:

<Label x:Name="lblFirstName" Content="First name:" Style="{StaticResource lblForm}" Grid.Row="1"/>

当我在 Blend 设计器中检查相同的标签元素时,FontSize 属性不是< /strong> 与样式中设置的相同。例如,当样式中的 FontSize 属性设置为 14 时,设计者表示 FontSize 为 10.5。如果我增加样式中的 FontSize 属性,当我在设计器中查看它时,它也会增加,但它永远不会相同。为什么会发生这种情况?

I have a label in a grid and I apply a style to it from a resource dictionary. The style changes, among other things, the FontSize property of the label to 14.

    <Style x:Key="lblForm" TargetType= "{x:Type Label}">
    <Setter Property="FontSize" Value="14"/>
    <Setter Property="Foreground" Value="Black"/>
    <Setter Property="HorizontalAlignment" Value="Right"/>
    <Setter Property="VerticalAlignment" Value="Center"/>
    <Setter Property="Margin" Value="0,0,6,0"/>
</Style>

I apply the style to the label in the following manner:

<Label x:Name="lblFirstName" Content="First name:" Style="{StaticResource lblForm}" Grid.Row="1"/>

When I inspect the same label element in the Blend designer, the FontSize property is not the same as that set in the style. For example, when the FontSize property is set to 14 in the style, the designer says the FontSize is 10.5. If I increase the FontSize property in the style it also increases when I view it in the designer, but it is never the same. Why is this happening?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

佞臣 2025-01-03 00:33:30

您可以通过不同的方式设置FontSize。来自 MSDN

qualifiedDouble 如前所述的双精度值,即
后跟以下单位声明字符串之一:px、in、cm、pt。

px(默认)是与设备无关的单位(每单位 1/96 英寸)

in 是英寸; 1英寸==96像素

cm是厘米; 1厘米==(96/2.54)像素

pt是点; 1pt==(96/72) 像素

在您的样式中,如果不明确设置它,则默认为 px
但是 Blend 计算时使用 pt 在此处输入图像描述

这就是两个值不同的原因。

You can set the FontSize in different ways. From MSDN:

<object FontSize ="qualifiedDouble"/>

qualifiedDouble A double value as previously described that is
followed by one of these unit declaration strings: px, in, cm, pt.

px (default) is device-independent units (1/96th inch per unit)

in is inches; 1in==96px

cm is centimeters; 1cm==(96/2.54) px

pt is points; 1pt==(96/72) px

In your style when don't set it explicitly it defaults to px.
But Blend calculates with pt enter image description here

That's why the two values are different.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文