TextBlock.Foreground 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.
public:
property System::Windows::Media::Brush ^ Foreground { System::Windows::Media::Brush ^ get(); void set(System::Windows::Media::Brush ^ value); };
public System.Windows.Media.Brush Foreground { get; set; }
member this.Foreground : System.Windows.Media.Brush with get, set
Public Property Foreground As Brush
Nilai Properti
Kuas yang digunakan untuk menerapkan ke konten teks. Defaultnya adalah Black.
Contoh
Contoh berikut menunjukkan cara mengatur Foreground 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 Foreground 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
Untuk tabel swatch yang menunjukkan warna kuas yang telah ditentukan sebelumnya yang tersedia, lihat Brushes.
Pengaturan apa pun Foreground pada elemen turunan mengambil alih pengaturan tingkat atas ini.
Properti dependensi ini juga memiliki penggunaan properti terlampir. Dalam XAML, penggunaannya adalah <object TextBlock.Foreground="value".../>, di mana objek adalah elemen objek (biasanya elemen alur) yang terkandung dalam TextBlock, dan nilai adalah string yang diselesaikan ke Brush nilai implementasi. Dalam kode, penggunaan properti terlampir didukung oleh GetForeground dan SetForeground. Penggunaan properti terlampir tidak umum, karena sebagian besar elemen yang dapat dimuat dalam TextBlock mendukung properti yang tidak terpasang Foreground analog, yang digunakan untuk penyajian TextBlock .
Informasi Properti Dependensi
| Item | Nilai |
|---|---|
| Bidang pengidentifikasi | ForegroundProperty |
Properti metadata diatur ke true |
AffectsRender, , SubPropertiesDoNotAffectRenderInherits |