TextBlock.LineHeight 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定每行內容的高度。
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>
下列示範如何以程式設計的方式設定 Typography 屬性。
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
除了這個性質外,a TextBlock 中線條的佈局也會受到其 LineStackingStrategy 性質的影響。
此依賴性質也有附加財產使用。 在 XAML 中,用法為 <object TextBlock.LineHeight="value".../>,其中 物件 是包含在 TextBlock、 中的物件元素(通常是流程元素),而 值 則是字串,詳見 XAML 的值。 在程式碼中,附加屬性的使用由 和 SetLineHeight支援GetLineHeight。 附帶房產的使用並不常見。
XAML 屬性使用方式
<object LineHeight="double"/>
- or -
<object LineHeight="qualifiedDouble"/>
- or -
<object LineHeight="Auto"/>
XAML 值
雙重Double
一個等於或大0.0034於且等於或小於160000的值的字串表示Double。 未限定值以裝置獨立像素為單位。 字串不必明確包含小數點。
取得雙重資格如上所述的雙重值(不含 Auto),後接以下單位指定符之一:px, in, cmpt, 。
px (預設)為裝置無關單位(每單位 1/96 吋)
in 是英吋;1in==96px
cm 是公分;1cm==(96/2.54) px
pt 是分數;1pt==(96/72) px
自動 會自動根據目前字型特性決定行高。 等價於財產價值為 Double.NaN。
相依財產資訊
| 項目 | 價值 |
|---|---|
| 識別碼欄位 | LineHeightProperty |
元資料屬性設為 true |
AffectsMeasure、AffectsRender、Inherits |