TextBlock中字体上升线上方的空白区域

时间:2013-06-17 20:11:23

标签: silverlight xaml

我发现TextBlock顶部有一个空格,位于上升线上方(如图中的红色箭头所示),即使TextBlock.VerticalAlignment = Top,Padding = 0和TextBlock.Height = Auto。 有人知道为什么还有额外的空间吗?有没有办法在不指定TextBlock.Height和TextBlock.Margin的绝对值的情况下删除它?

以下是XAML代码:

<phone:PhoneApplicationPage
x:Class="PhoneApp1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True">

<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <!--TitlePanel contains the name of the application and page title-->
    <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
        <TextBlock Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}" Margin="12,0"/>
        <TextBlock Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
    </StackPanel>

    <!--ContentPanel - place additional content here-->
    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0" ShowGridLines="True">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>

        <TextBlock Height="Auto" FontWeight="Light" Text="aps" FontSize="100" Grid.Column="0" VerticalAlignment="Top" Padding="0" />
        <TextBlock Height="Auto" FontWeight="Light" Text="Sphinx" FontSize="100" Grid.Column="1" VerticalAlignment="Top" Padding="0" />
    </Grid>
</Grid>

1 个答案:

答案 0 :(得分:0)

空格是行间距的结果。一种解决方案是设置TextBlock的其他属性:

<TextBlock LineHeight="80" LineStackingStrategy="BlockLineHeight" 

但是,您必须自己计算LineHeight,它会因字体和字体之间以及尺寸而异,但这是将文本放在所需行的最简单方法。如果这是不可接受的,既然你知道问题的根源,那么你可以寻找更通用的解决方案。