Share via


TextBlock.LineHeight Properti

Definisi

Mendapatkan atau mengatur tinggi setiap baris konten.

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

Nilai Properti

Tinggi garis, dalam piksel independen perangkat, dalam rentang 0,0034 hingga 160000. Nilai NaN (setara dengan nilai atribut "Auto") menunjukkan bahwa tinggi baris ditentukan secara otomatis dari karakteristik font saat ini. Default adalah NaN.

Atribut

Pengecualian

LineHeight diatur ke nilai non-positif.

Contoh

Contoh berikut menunjukkan cara mengatur LineHeight atribut TextBlock elemen.

<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>

Contoh berikut menunjukkan cara mengatur LineHeight properti secara terprogram.

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

Keterangan

Mengubah nilai ini tidak mengubah tinggi teks terkait; sebaliknya, itu mengubah tinggi baris yang berisi teks. Untuk mengubah ukuran teks, gunakan FontSize properti .

Selain properti ini, tata letak garis dalam dipengaruhi TextBlock oleh propertinya LineStackingStrategy .

Properti dependensi ini juga memiliki penggunaan properti terlampir. Dalam XAML, penggunaannya adalah <object TextBlock.LineHeight="value".../>, di mana objek adalah elemen objek (biasanya elemen alur) yang terkandung dalam TextBlock, dan nilai adalah string seperti yang dijelaskan dalam Nilai XAML. Dalam kode, penggunaan properti terlampir didukung oleh GetLineHeight dan SetLineHeight. Penggunaan properti terlampir tidak umum.

Penggunaan Atribut XAML

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

Nilai XAML

double
Double

Representasi string dari nilai yang Double sama dengan atau lebih besar dari 0.0034 dan sama dengan atau kurang dari kemudian 160000. Nilai yang tidak memenuhi syarat diukur dalam piksel independen perangkat. String tidak perlu secara eksplisit menyertakan titik desimal.

qualifiedDouble
Nilai ganda seperti yang dijelaskan di atas, (kecuali Auto) diikuti oleh salah satu penentu unit berikut: px, , in, cm. pt

px (default) adalah unit independen perangkat (1/96 inci per unit)

in adalah inci; 1in==96px

cm adalah sentimeter; 1cm==(96/2,54) px

pt adalah poin; 1pt==(96/72) px

Otomatis
Menyebabkan tinggi garis ditentukan secara otomatis dari karakteristik font saat ini. Setara dengan nilai properti .Double.NaN

Informasi Properti Dependensi

Bidang pengidentifikasi LineHeightProperty
Properti metadata diatur ke true AffectsMeasure, AffectsRender, Inherits

Berlaku untuk

Lihat juga