Search code examples
wpfwpf-controlstextblock

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?


Solution

  • 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