Jeff
Jeff

Reputation: 53

WPF textblock shifts with placement of attribute

Why is it when using the different ways of expressing attributes the textblock shifts?

<TextBlock  Canvas.Left="0"  Canvas.Top="0"  FontSize="72" >
        <TextBlock.Foreground>Red
        </TextBlock.Foreground>

        DIET
    </TextBlock>

verses

    <TextBlock  Canvas.Left="0"  Canvas.Top="0"  FontSize="72" Foreground="Red">

        DIET
    </TextBlock>

The later is more left then the first. Is there a reason for this?

Upvotes: 1

Views: 158

Answers (2)

Fredrik Hedblad
Fredrik Hedblad

Reputation: 84647

Well, there is no reason for this and there isn't any difference, just a bug in the Visual Studio Designer. Try it in runtime and see for yourself :)

Comparison between Visual Studio 2010 Designer, Blend and Runtime with the following Xaml

<Canvas>
    <TextBlock Canvas.Left="0" Canvas.Top="0" FontSize="72">
        <TextBlock.Foreground>Red</TextBlock.Foreground>
        DIET
    </TextBlock>
    <TextBlock Canvas.Left="0" Canvas.Top="100" FontSize="72" Foreground="Red">
        DIET
    </TextBlock>
</Canvas>

enter image description here

Upvotes: 3

Stefan Dragnev
Stefan Dragnev

Reputation: 14473

How much to the left? It may be due to Subpixel sampling - the red LED of a pixel may be on its left side and it will look as if the text has shifted by 2/3 of a pixel. Try Foreground="Blue" and if its shifted slightly to the right, then this is the problem. Just live with it.

Upvotes: 0

Related Questions