TextElement.Foreground 屬性

定義

取得或設定要套用至專案內容的筆刷。

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

屬性值

Brush

用來套用至文字內容的筆刷。 預設為 Black

範例

下列範例示範如何使用 做為範例專案來設定 Foreground 屬性 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>

下圖顯示上述範例的呈現方式。

螢幕擷取畫面:前景為綠色,背景為淡黃色

下列範例示範如何以程式設計方式設定 Foreground 屬性。

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

此相依性屬性也有附加屬性使用方式。 在 XAML 中,用法是 <object TextElement.Foreground="value".../> ,其中 object 是物件 元素, (通常流程元素) 包含在 中 TextElement ,而 value 是解析為 Brush 實作值的字串。 在程式碼中,和 SetForeground 方法支援 GetForeground 附加屬性使用方式。 附加屬性使用方式並不常見,因為大部分可以包含在 中的 TextElement 元素都支援類似非附加 Foreground 屬性,內容主機會用來轉譯。

相依性屬性資訊

識別碼欄位 ForegroundProperty
中繼資料屬性設定為 true AffectsRenderInheritsSubPropertiesDoNotAffectRender

適用於

另請參閱