次の方法で共有


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

プロパティ値

テキストの内容に適用するために使用されるブラシ。 既定値は、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".../>です。 ここで、オブジェクトTextElement内に含まれるオブジェクト要素 (通常はフロー要素) であり、 Brush 実装値に解決される文字列です。 コードでは、添付プロパティの使用は、 GetForeground メソッドと SetForeground メソッドでサポートされています。 添付プロパティの使用方法は一般的ではありません。 TextElement に含めることができるほとんどの要素は、コンテンツ ホストがレンダリングに使用する類似した非アタッチ Foreground プロパティをサポートしているためです。

依存関係プロパティ情報

品目 価値
識別子フィールド ForegroundProperty
に設定されたメタデータ プロパティ true AffectsRenderInheritsSubPropertiesDoNotAffectRender

適用対象

こちらもご覧ください