TextBlock.LineHeight 屬性

定義

取得或設定每行內容的高度。

public:
 property double LineHeight { double get(); void set(double value); };
[System.ComponentModel.TypeConverter(typeof(System.Windows.LengthConverter))]
public double LineHeight { get; set; }
[<System.ComponentModel.TypeConverter(typeof(System.Windows.LengthConverter))>]
member this.LineHeight : double with get, set
Public Property LineHeight As Double

屬性值

範圍從 0.0034 到 160000 的行高 (以與裝置無關的像素為單位)。 NaN 的值 (相當於 "Auto" 的屬性值) 表示行高是由目前字型特性自動決定。 預設值為 NaN

屬性

例外狀況

LineHeight 會設為非正數值。

範例

下列範例示範如何設定 LineHeight 專案的 屬性 TextBlock

<TextBlock 
  Name="textBlock"
  
  Background="AntiqueWhite" 
  Foreground="Navy" 
  
  FontFamily="Century Gothic"
  FontSize="12"
  FontStretch="UltraExpanded"
  FontStyle="Italic"
  FontWeight="UltraBold"
  
  LineHeight="Auto"
  Padding="5,10,5,10"
  TextAlignment="Center"
  TextWrapping="Wrap"
  
  Typography.NumeralStyle="OldStyle"
  Typography.SlashedZero="True"
>
  <Run Background="LightGreen">Text run 1.</Run>
  <LineBreak/><Run Background="LightBlue">Text run 2.</Run>
  <LineBreak/><Run Background="LightYellow">Text run 3.</Run>
</TextBlock>

下列範例示範如何以程式設計方式設定 LineHeight 屬性。

TextBlock textBlock = new TextBlock(new Run("A bit of text content..."));

textBlock.Background              = Brushes.AntiqueWhite;
textBlock.Foreground              = Brushes.Navy;

textBlock.FontFamily              = new FontFamily("Century Gothic");
textBlock.FontSize                = 12;
textBlock.FontStretch             = FontStretches.UltraExpanded;
textBlock.FontStyle               = FontStyles.Italic;
textBlock.FontWeight              = FontWeights.UltraBold;

textBlock.LineHeight              = Double.NaN;
textBlock.Padding                 = new Thickness(5, 10, 5, 10);
textBlock.TextAlignment           = TextAlignment.Center;
textBlock.TextWrapping            = TextWrapping.Wrap;

textBlock.Typography.NumeralStyle = FontNumeralStyle.OldStyle;
textBlock.Typography.SlashedZero  = true;
Dim textBlock As New TextBlock(New Run("A bit of text content..."))

textBlock.Background = Brushes.AntiqueWhite
textBlock.Foreground = Brushes.Navy

textBlock.FontFamily = New FontFamily("Century Gothic")
textBlock.FontSize = 12
textBlock.FontStretch = FontStretches.UltraExpanded
textBlock.FontStyle = FontStyles.Italic
textBlock.FontWeight = FontWeights.UltraBold

textBlock.LineHeight = Double.NaN
textBlock.Padding = New Thickness(5, 10, 5, 10)
textBlock.TextAlignment = TextAlignment.Center
textBlock.TextWrapping = TextWrapping.Wrap

textBlock.Typography.NumeralStyle = FontNumeralStyle.OldStyle
textBlock.Typography.SlashedZero = True

備註

變更此值並不會變更相關聯文字的高度;相反地,它會變更包含文字之行的高度。 若要變更文字的大小,請使用 FontSize 屬性。

除了這個屬性之外,中的 TextBlock 線條配置也會受到其 LineStackingStrategy 屬性的影響。

此相依性屬性也有附加屬性使用方式。 在 XAML 中,使用方式是 <object TextBlock.LineHeight="value".../> ,其中 object 是物件元素 (通常是流程元素) 包含在 中 TextBlock ,而 是 XAML 值中所述的字串。 在程式碼中,和 SetLineHeight 支援 GetLineHeight 附加屬性使用方式。 附加屬性使用方式並不常見。

XAML Attribute Usage

<object LineHeight="double"/>  
- or -  
<object LineHeight="qualifiedDouble"/>  
- or -  
<object LineHeight="Auto"/>  

XAML 值

double
Double

值等於或大於 0.0034 或等於或等於或小於 的字串表示 Double ,則為 160000 。 不合格的值是以裝置獨立圖元來測量。 字串不需要明確包含小數點。

qualifiedDouble
如上所述的 雙精度 浮點數,除了) 後面接著下列其中一個單位規範之外 Auto , (: pxincmpt

px (預設) 是裝置獨立單位 (,每單位 1/96 英吋)

in 為英吋;1in==96px

cm 為公分;1cm== (96/2.54) px

pt 為點;1pt== (96/72) px

自動
使線條高度從目前的字型特性自動決定。 相當於 的 Double.NaN 屬性值。

相依性屬性資訊

識別碼欄位 LineHeightProperty
設定為 的中繼資料屬性 true AffectsMeasure, AffectsRender, Inherits

適用於

另請參閱