【问题标题】:The blank space above font ascender line in TextBlockTextBlock中字体上升线上方的空格
【发布时间】:2013-06-17 20:11:22
【问题描述】:

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

【问题讨论】:

标签: silverlight xaml


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 2013-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-17
    • 2011-09-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多