开发者

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

    <Tex开发者_运维知识库tBlock  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?


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>

WPF textblock shifts with placement of attribute


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜