TextBlock.FontFamily Properti
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Mendapatkan atau mengatur keluarga font tingkat atas pilihan untuk TextBlock.
public:
property System::Windows::Media::FontFamily ^ FontFamily { System::Windows::Media::FontFamily ^ get(); void set(System::Windows::Media::FontFamily ^ value); };
[System.Windows.Localizability(System.Windows.LocalizationCategory.Font)]
public System.Windows.Media.FontFamily FontFamily { get; set; }
[<System.Windows.Localizability(System.Windows.LocalizationCategory.Font)>]
member this.FontFamily : System.Windows.Media.FontFamily with get, set
Public Property FontFamily As FontFamily
Nilai Properti
Objek FontFamily yang menentukan keluarga font pilihan, atau keluarga font pilihan utama dengan satu atau beberapa keluarga font fallback. Defaultnya adalah font yang ditentukan oleh MessageFontFamily nilai .
- Atribut
Contoh
Contoh berikut menunjukkan cara mengatur FontFamily 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 properti FontFamily 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 FontFamily pada elemen turunan mengambil alih pengaturan tingkat atas ini.
Ketika beberapa keluarga ditentukan, keluarga font kedua dan berikutnya berfungsi sebagai keluarga fallback yang akan digunakan dalam kasus di mana keluarga font utama tidak tersedia atau tidak berlaku.
Properti ini hanya menentukan preferensi. Jika keluarga font yang ditentukan tidak tersedia, diam-diam TextBlock kembali ke font yang ditentukan oleh MessageFontFamily nilai .
Properti dependensi ini juga memiliki penggunaan properti terlampir. Dalam XAML, penggunaannya adalah <object TextBlock.FontFamily="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 GetFontFamily dan SetFontFamily. Penggunaan properti terlampir tidak umum, karena sebagian besar elemen yang dapat dimuat dalam TextBlock mendukung properti yang tidak terpasang FontFamily analog, yang digunakan untuk penyajian TextBlock .
Penggunaan Atribut XAML
<object FontFamily="fontFamilyName"/>
- or -
<object FontFamily="fontFamilyNamesList"/>
- or -
<object FontFamily="fontFamilyFolderReference"/>
- or -
<object FontFamily="fontFamilyUriReference"/>
Nilai XAML
fontFamilyName String yang menentukan nama keluarga font. Misalnya, "Arial" atau "Century Gothic".
fontFamilyNamesList String yang menentukan beberapa nama keluarga font, masing-masing dipisahkan oleh koma (spasi kosong setelah koma diabaikan). Keluarga font pertama yang ditentukan berfungsi sebagai keluarga font utama; keluarga font berikutnya berfungsi sebagai keluarga fallback yang akan digunakan dalam kasus di mana keluarga font utama tidak tersedia atau tidak berlaku. Misalnya, "Arial, Century Gothic" menentukan Arial sebagai keluarga font utama, dengan Century Gothic sebagai keluarga font fallback.
fontFamilyFolderReference String yang menentukan folder yang berisi font, bersama dengan nama keluarga font. Folder dan nama keluarga font dibatasi oleh karakter # . Referensi folder mungkin absolut, atau relatif. Contohnya, "Custom Fonts\#My Custom Font".
fontFamilyUriReference String yang menentukan pengidentifikasi sumber daya seragam (URI) untuk font, bersama dengan nama keluarga font. URI dan nama keluarga font dibatasi oleh karakter # . Contohnya, "http://MyFontServer/Fonts/#My Custom Font".
Informasi Properti Dependensi
| Item | Nilai |
|---|---|
| Bidang pengidentifikasi | FontFamilyProperty |
Properti metadata diatur ke true |
AffectsMeasure, , AffectsRenderInherits |