Share via


TextBlock.FontSize Properti

Definisi

Mendapatkan atau mengatur ukuran font tingkat atas untuk TextBlock.

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

Nilai Properti

Ukuran font yang diinginkan untuk digunakan dalam piksel independen perangkat). Default ditentukan oleh MessageFontSize nilai .

Atribut

Contoh

Contoh berikut menunjukkan cara mengatur FontSize 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 FontSize 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

Pengaturan apa pun FontSize pada elemen turunan mengambil alih pengaturan tingkat atas ini.

Properti dependensi ini juga memiliki penggunaan properti terlampir. Dalam XAML, penggunaannya adalah <object TextBlock.FontSize="value".../>, di mana objek adalah elemen objek (biasanya elemen alur) yang terkandung dalam TextBlock, dan nilai adalah salah satu nilai format string seperti yang dijelaskan dalam Nilai XAML. Dalam kode, penggunaan properti terlampir didukung oleh GetFontSize dan SetFontSize. Penggunaan properti terlampir tidak umum, karena sebagian besar elemen yang dapat dimuat dalam TextBlock mendukung properti yang tidak terpasang FontSize analog, yang TextBlock digunakan untuk penyajian.

Penggunaan Atribut XAML

<object FontSize="double"/>  
- or -  
<object FontSize="qualifiedDouble"/>  

Nilai XAML

double
Double

Representasi string dari nilai yang Double sama dengan atau lebih besar dari 0,0 tetapi lebih kecil dari PositiveInfinity. 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, diikuti oleh salah satu penentu unit berikut: px, , incm, . 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

Informasi Properti Dependensi

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

Berlaku untuk