TextBlock.Background Propriété

Définition

Obtient ou définit le Brush utilisé pour remplir l'arrière-plan de la zone de contenu.Gets or sets the Brush used to fill the background of content area.

public:
 property System::Windows::Media::Brush ^ Background { System::Windows::Media::Brush ^ get(); void set(System::Windows::Media::Brush ^ value); };
public System.Windows.Media.Brush Background { get; set; }
member this.Background : System.Windows.Media.Brush with get, set
Public Property Background As Brush

Valeur de propriété

Brush

Pinceau permettant de remplir l'arrière-plan de la zone du contenu, ou null pour ne pas utiliser de pinceau d'arrière-plan.The brush used to fill the background of the content area, or null to not use a background brush. La valeur par défaut est null.The default is null.

Exemples

L’exemple suivant montre comment définir l' Background attribut d’un TextBlock élément.The following example shows how to set the Background attribute of a TextBlock element.

<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 Background propriété par programmation.The following example shows how to set the Background property programmatically.

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

Tous les Background paramètres des éléments enfants remplacent ce paramètre de niveau supérieur.Any Background settings on child elements override this top-level setting.

Pour obtenir un tableau des nuanciers qui montrent les couleurs de pinceau prédéfinies disponibles, consultez Brushes .For a table of swatches that show the available predefined brush colors, see Brushes.

Informations sur les propriétés de dépendanceDependency Property Information

Champ d’identificateurIdentifier field BackgroundProperty
Propriétés de métadonnées définies sur trueMetadata properties set to true AffectsRender

S’applique à