Search code examples
wpfsilverlighttextblock

Silverlight 3 TextBlock leaves blank space above text


I have the following in my XAML:

<Grid x:Name="LayoutRoot" Background="White">
    <Grid.RowDefinitions>
        <RowDefinition Height="20"/>
        <RowDefinition Height="7"/>
        <RowDefinition Height="57"/>
    </Grid.RowDefinitions>

    <TextBlock Grid.Row="0" FontSize="18">Title Text</TextBlock>

    <Rectangle Grid.Row="1" Margin="0,2" Height="3" HorizontalAlignment="Stretch" Fill="#ff000000"/>

    <Border Grid.Row="2" Margin="0" Padding="0" BorderBrush="Black" BorderThickness="1">
        <TextBlock Margin="0" Padding="0" FontSize="55">123</TextBlock>
    </Border>
</Grid>

The problem is that there is a space (about 10px) above the text in the bottom TextBlock. I can only seem to get rid of this space by using a much smaller font size.

Does anyone have an idea of why this space is showing up, and what I can do about it?

Thank you.


Solution

  • I believe it is because the default VerticalAlignment on a TextBlock is Stretch. Try setting it to Center:

    <TextBlock Margin="0" Padding="0" FontSize="55" VerticalAlignment="Center">123</TextBlock>
    

    If you really need to nudge it up you could add a negative top margin.