TextElement.Background 属性

定义

获取或设置用于填充内容区域背景的画笔。

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(不使用背景画笔)。 默认值为 null

示例

以下示例演示如何使用示例元素设置 Background 属性 Paragraph

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

下图显示了上述示例的呈现方式。

屏幕快照:前景为绿色,背景为橘黄色

以下示例演示如何以编程方式设置 Background 属性。

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

注解

有关显示可用预定义画笔颜色的表,请参阅 Brushes

依赖项属性信息

标识符字段 BackgroundProperty
元数据属性设置为 true AffectsRender

适用于

另请参阅