TextBlock.Foreground Propriété

Définition

Obtient ou définit le Brush à appliquer au contenu textuel de TextBlock.

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

Valeur de propriété

Brush

Pinceau à appliquer au contenu de texte. La valeur par défaut est Black.

Exemples

L’exemple suivant montre comment définir l’attribut Foreground d’un TextBlock élément.

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

L’exemple suivant montre comment définir la Foreground propriété par programmation.

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

Remarques

Pour obtenir un tableau de montres qui affichent les couleurs de pinceau prédéfinis disponibles, consultez Brushes.

Tous les Foreground paramètres des éléments enfants remplacent ce paramètre de niveau supérieur.

Cette propriété de dépendance a également une utilisation de propriété jointe. En XAML, l’utilisation est <object TextBlock.Foreground="value".../>, où l’objet est un élément d’objet (généralement un élément de flux) contenu dans un TextBlock, et la valeur est une chaîne qui se résout en une valeur d’implémentation Brush . Dans le code, l’utilisation des propriétés jointes est prise en charge par GetForeground et SetForeground. L’utilisation des propriétés jointes n’est pas courante, car la plupart des éléments qui peuvent être contenus dans une TextBlock propriété de prise en charge analogue non attachée Foreground , utilisée pour le TextBlock rendu.

Informations sur les propriétés de dépendance

Champ d’identificateur ForegroundProperty
Propriétés de métadonnées définies sur true AffectsRender, SubPropertiesDoNotAffectRender, Inherits

S’applique à