Style 中设置的 FontSize 与 Blend 中的 FontSize 不匹配
我在网格中有一个标签,并从资源字典中应用了样式。除其他事项外,样式将标签的 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过不同的方式设置
FontSize
。来自 MSDN:在您的样式中,如果不明确设置它,则默认为 px。
但是 Blend 计算时使用 pt
这就是两个值不同的原因。
You can set the
FontSize
in different ways. From MSDN:In your style when don't set it explicitly it defaults to px.
But Blend calculates with pt
That's why the two values are different.