2016-02-27 149 views
0

我有一个TextBlock,我想在其中显示不同字体大小的两行文本,但我不希望每行上面都浪费空间。WPF:减少/删除TextBlock中文本上方的空白空间

我的XAML是如下...

<TextBlock Grid.Column="0" Grid.Row="0" FontWeight="Bold" Foreground="Red" TextAlignment="Center"> 

    <Run Text="A" FontSize="144" FontWeight="Bold" /> 

    <LineBreak /> 

    <Run Text="Service" FontSize="18" /> 

</TextBlock> 

什么我最终是...

An image of what I actually get from my XAML

而我要的是...

An image of what I am trying to acheive

注意“A”之上的所有浪费空间,以及b在“A”和“Service”行之间(我已经通过操作图像在第二个图像中删除了这个)。

我已经尝试了LineHeight,LineStackingStrategy,Margin和Padding属性值的各种组合,不仅针对TextBlock,还针对段落(使用样式),但没有任何东西似乎删除空间。

有人可以建议我应该如何实现这一点;我相信它一定是可能的。

谢谢。

+0

提供服务负余量不起作用?例如:'Margin =“0 -4 0 0”' – Peter

回答

2

你可以使用LineStackingStrategy属性设置为BlockLineHeight并指定一个LineHeight来获得你想要的。

<TextBlock Grid.Column="0" Grid.Row="0" FontWeight="Bold" Foreground="Red" TextAlignment="Center" 
      LineHeight="15.25" 
      LineStackingStrategy="BlockLineHeight"> 
    <Run Text="A" FontSize="144" FontWeight="Bold" /> 
    <LineBreak /> 
    <Run Text="Service" FontSize="18" /> 
</TextBlock> 

Result

+0

感谢你们,我最终使用了这种技术,但实现了使用答案[这里](http://stackoverflow.com/questions/9785322/textblock-as-big -as-A-资本字母忽略的字体,伸,伸#15876463)。 –

0

我不认为这会正是变成您正在搜索的方式,但你可以试试。

TextBlock转换为DockPanelStackPanel,然后按照您的偏好设置,然后将其中一个设为ViewBox

ViewBox试图最大限度地提高它包含的相对于wpf窗口的分辨率。

TextBlock置于StackPanel的原因是因为ViewBox不接受多个孩子。