2016-02-27 60 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不接受多個孩子。