wpf - 如何改变文本 block 的高度

标签 wpf xaml

围绕文本的文本 block 背景宽度非常窄。但是,顶部和底部非常大。我如何缩小这个空间?我无法通过设置高度来做到这一点,也无法为其附加负填充。

 <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

最佳答案

可以利用元素的Height来减少底部的空间,可以结合TextWrappingLineHeight LineStackingStrategy调整元素顶部的空间:

<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

关于wpf - 如何改变文本 block 的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52858836/

相关文章:

C# TWAIN 交互

c# - 我应该为每个模型都有一个封装的 ViewModel 吗?

c# - WPF 绑定(bind)到变量/DependencyProperty

c# - 如何滚动网格?

xaml - 全局路由当前不能是堆栈中的唯一页面

c# - 选择字体大小以使字符串适合宽度

c# - 将 Dictionary<string,List<Class>> 绑定(bind)到多个 TreeViewItem

c# - 如何在 WPF MVVM 中将 View 的变量绑定(bind)到 ViewModel?

c# - 在数据网格中搜索

c# - 向类型 'System.Windows.Controls.ItemCollection' 的集合添加值引发异常