TextElement.Background Property

Definition

Gets or sets the brush used to fill the background of the content area.

public System.Windows.Media.Brush Background { get; set; }

Property Value

The brush used to fill the background of the content area, or null to not use a background brush. The default is null.

Examples

The following example shows how to set the Background attribute, using Paragraph as the example element.

<FlowDocumentReader>
  <FlowDocument>
    <Paragraph
      Background="Bisque"
      Foreground="DarkGreen"
      Padding="4"
    >
      <Run>
        This text has a foreground color of dark green, and a background color of bisque.
      </Run>
    </Paragraph>
  </FlowDocument>
</FlowDocumentReader>

The following figure shows how the preceding example renders.

Screenshot: Foreground of green, background bisque

The following example shows how to set the Background property programmatically.

Run run = new Run(
    "This text has a foreground color of dark green, and a background color of bisque.");
Paragraph par = new Paragraph(run);

par.Background = Brushes.Bisque;
par.Foreground = Brushes.DarkGreen;

Remarks

For a table of swatches that show the available predefined brush colors, see Brushes.

Dependency Property Information

Item Value
Identifier field BackgroundProperty
Metadata properties set to true AffectsRender

Applies to

Produkt Wersje
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

See also