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?
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
That's why the two values are different.