TarkaDaal
TarkaDaal

Reputation: 19595

Fonts in designer are different size to those at runtime

I have a Silverlight OOB application. Some of the TextBlocks (but not all) have started to behave strangely. When viewed in the Designer, they're the size I want them to be. When I run the app, they appear roughly 1pt bigger.

I've checked it with Silverlight Spy, and the font size/weight are the same as at design time. If I make the fonts too small in design mode, they come out the right size at runtime. If I use Silverlight Spy to make them 1pt too small at runtime, they look the right size. Silverlight Spy shows that the TextBlocks aren't affected by a style.

What could be causing this? I'm using VS 2010 and Silverlight 5.

Upvotes: 4

Views: 884

Answers (3)

komodosp
komodosp

Reputation: 3616

I had this problem with Labels, Buttons and Checkboxes. After a look using WPF inspector, it had come to my attention that the text in each of the above contains a TextBlock to display the actual text, and I had set my default FontSize for a Text Block to 13 which was then overriding the value I specified for (e.g) the Label.

This sorted me out

<ControlTemplate x:Key="LabelTemplate" TargeType="Label">
    <TextBlock Text="{TemplateBinding Content}" FontSize="{TemplateBinding FontSize}" />
</ControlTemplate>


<Style TargetType="{x:Type Label}">
    <Setter ... etc. etc. other styling I had already in here />
    <Setter Property="Template" Value="{StaticResource LabelTemplate}" />
</Style>

Upvotes: 0

Mike Strobel
Mike Strobel

Reputation: 25623

In cases where I have observed differences in font rendering in WPF or Silverlight, it was almost always due to the FontFamily being different rather than the FontSize. If you can, verify with Silverlight Spy that the font families are in fact the same.

Interestingly, there can be differences even if the effective font family is the same. In one of our applications, we are using a composite FontFamily definition that uses Segoe UI for most western glyph ranges, but a serifed font for the Greek glyph ranges to better differentiate those characters (this is a finance application). I noticed that the line height was slightly different in the editor than in the runtime application. It seems the editor doesn't always apply composite fonts correctly (or didn't, prior to some of the VS2012 updates).

Upvotes: 2

Benjamin
Benjamin

Reputation: 1173

Check if there are any Transforms present.

Upvotes: 0

Related Questions