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 値で説明されている文字列です。 コードでは、添付プロパティの使用法は と SetLineHeightGetLineHeightサポートされています。 添付プロパティの使用方法は一般的ではありません。

XAML 属性の使用方法

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

XAML 値

double
Double

以上の値0.0034Double文字列表現。次160000に と等しいか、次に等しいか小さい。 非修飾値は、デバイスに依存しないピクセル単位で測定されます。 文字列に小数点を明示的に含める必要はありません。

qualifiedDouble
前述の double 値 (を除く Auto) の後に、次のいずれかの単位指定子 px(、 incmpt) が続きます。

px (既定値) はデバイスに依存しない単位 (ユニットあたり 1/96 インチ) です

in はインチ。1in==96px

cm はセンチメートルです。1cm==(96/2.54) px

pt はポイント。1pt==(96/72) px

自動
現在のフォント特性から行の高さを自動的に決定します。 のプロパティ値 Double.NaNに相当します。

依存プロパティ情報

識別子フィールド LineHeightProperty
に設定されたメタデータ プロパティ true AffectsMeasure, AffectsRender, Inherits

適用対象

こちらもご覧ください