【问题标题】:FontSize set in Style does not match FontSize in BlendStyle 中设置的 FontSize 与 Blend 中的 FontSize 不匹配
【发布时间】:2012-02-10 07:02:09
【问题描述】:

我在网格中有一个标签,我从资源字典中应用了一个样式。样式更改,除其他外,标签的 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 属性与样式中设置的相同。例如,当样式中的 FontSize 属性设置为 14 时,设计者说 FontSize 为 10.5。如果我在样式中增加 FontSize 属性,当我在设计器中查看它时它也会增加,但它永远不会相同。为什么会这样?

【问题讨论】:

    标签: wpf expression-blend font-size


    【解决方案1】:

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

    &lt;object FontSize ="qualifiedDouble"/&gt;

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

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

    in 是英寸; 1in==96px

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

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

    在您的样式中,如果不明确设置它,则默认为 px。 但是 Blend 使用 pt

    计算

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

    【讨论】:

    • 谢谢!我不敢相信我没有想到这一点。
    猜你喜欢
    • 1970-01-01
    • 2012-11-11
    • 1970-01-01
    • 2019-04-23
    • 2018-05-05
    • 1970-01-01
    • 2016-08-27
    • 1970-01-01
    • 2019-12-11
    相关资源
    最近更新 更多