Dela via


RichTextBlock.Foreground Property

Definition

Gets or sets the Brush to apply to the text contents of the RichTextBlock.

public:
 property Brush ^ Foreground { Brush ^ get(); void set(Brush ^ value); };
Brush Foreground();

void Foreground(Brush value);
public Brush Foreground { get; set; }
var brush = richTextBlock.foreground;
richTextBlock.foreground = brush;
Public Property Foreground As Brush
<RichTextBlock Foreground="{StaticResource resourceName}"/>
- or -
<RichTextBlock Foreground="colorString"/>
- or -
<RichTextBlock>
  <RichTextBlock.Foreground>singleBrush</RichTextBlock.Foreground>
</RichTextBlock>

Property Value

The brush used to apply to the text contents. The default is a null brush from a pure code perspective, but the default text styles set this to Black (for Light theme) or White (for Dark theme) for a TextBlock element in UI.

Remarks

Set the Foreground property to specify the default brush to use for all text in the RichTextBlock. You can override this value for specific text elements (such as a Run) in the RichTextBlock by setting the TextElement.Foreground property.

The default appearance of text and text styles depends heavily on the active theme and other settings. The theme and various styles and behaviors that are using default system settings or user preferences are the source of the effective runtime appearance of RichTextBlock foreground color of text as well as other text characteristics. You can change these defaults by changing the property values, or by applying a different style to specific RichTextBlock instances. You can change the foreground value for all default text by overriding the resource named DefaultTextForegroundThemeBrush in App.xaml.

Applies to

See also