TextElement.Foreground Property
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets or sets the brush to apply to the content of the element.
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
The brush used to apply to the text contents. The default is Black.
The following example shows how to set the Foreground 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.
The following example shows how to set the Foreground 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
For a table of swatches that shows the available predefined brush colors, see Brushes.
This dependency property also has an attached property usage. In XAML, the usage is <object TextElement.Foreground="value".../>
, where object is an object element (typically a flow element) contained within a TextElement, and value is a string that resolves to a Brush implementation value. In code, the attached property usage is supported by the GetForeground and SetForeground methods. The attached property usage is not common, because most elements that can be contained in a TextElement support an analogous nonattached Foreground
property, which the content host uses for rendering.
Identifier field | ForegroundProperty |
Metadata properties set to true |
AffectsRender, Inherits, SubPropertiesDoNotAffectRender |
Product | Versions |
---|---|
.NET Framework | 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
Windows Desktop | 3.0, 3.1, 5, 6, 7, 8, 9 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: