TextElement.Background 属性

定义

获取或设置用于填充内容区域背景的画笔。Gets or sets the brush used to fill the background of the 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

属性值

Brush

用于填充内容区域背景的画笔,或 null(不使用背景画笔)。The brush used to fill the background of the content area, or null to not use a background brush. 默认值为 nullThe default is null.

示例

下面的示例演示如何 Background 使用 Paragraph 作为示例元素来设置特性。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

下面的示例演示如何以 Background 编程方式设置属性。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;
Dim run As New Run("This text has a foreground color of dark green, and a background color of bisque.")
Dim par As New Paragraph(run)

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

注解

有关显示可用预定义画笔颜色的样本表,请参阅 BrushesFor a table of swatches that show the available predefined brush colors, see Brushes.

依赖项属性信息Dependency Property Information

标识符字段Identifier field BackgroundProperty
元数据属性设置为 trueMetadata properties set to true AffectsRender

适用于

另请参阅