1

我发现 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>

4

1 回答 1

0

空间是行间距的结果。一种解决方案可以设置以下属性TextBlock

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

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

于 2013-06-18T10:24:23.100 回答