如何更改文本块的高度

时间:2018-10-17 15:46:35

标签: wpf xaml

包围文本的文本块的背景宽度非常窄。但是,顶部和底部非常大。如何缩小此空间?我无法通过设置高度来做到这一点,也无法在其上附加负片。

 <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"></RowDefinition>
        </Grid.RowDefinitions>


        <TextBlock  FontSize="200"                                 
                    FontWeight="Bold"
                    Background="Black"
                    Foreground="White"  
                    Text="bla bla"
                    HorizontalAlignment="Center">
        </TextBlock>
    </Grid>

enter image description here

2 个答案:

答案 0 :(得分:2)

您可以使用元素的Height来减少底部的空间,可以组合TextWrappingLineHeightLineStackingStrategy来调整顶部的空间的元素:

<Grid>    
    <TextBlock  FontSize="200"                                 
            FontWeight="Bold"
            Background="Black"
            Foreground="White"  
            Text="bla bla"
            Padding="0"
            Margin="0"
            HorizontalAlignment="Center"
            TextWrapping="Wrap" 
            LineStackingStrategy="BlockLineHeight"
            LineHeight="200" 
            Height="180">
    </TextBlock>
</Grid>

结果:

Result

答案 1 :(得分:1)

您需要设置的属性是LineHeight,结合LineStackingStrategy =“ BlockLineHeight”

<TextBlock FontSize="72" 
    Background="Black" 
    Foreground="White" 
    FontWeight="Bold" 
    Text="Hello World" 
    LineHeight="72" 
    LineStackingStrategy="BlockLineHeight" /> 
相关问题