Foreground Property

TextElement.Foreground Property

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Gets or sets the Brush to apply to the content in this element.

Namespace:  System.Windows.Documents
Assembly:  System.Windows (in System.Windows.dll)
XMLNS for XAML: Not mapped to an xmlns.

public Brush Foreground { get; set; }
<textElement>
  <textElement.Foreground>
    singleBrush
  </textElement.Foreground>
</textElement>
<textElement Foreground="colorString"/>

XAML Values

singleBrush

Within opening and closing property elements for textElement.Foreground, exactly one object element for an object that derives from Brush. The object element is generally one of the following Windows Phone classes: ImageBrush, LinearGradientBrush, RadialGradientBrush, SolidColorBrush, or VideoBrush.

colorString

The Color for a SolidColorBrush expressed as an attribute string. This can be a named color, an RGB value, or an ScRGB value. RGB or ScRGB may also specify alpha information. See Color.

Property Value

Type: System.Windows.Media.Brush
The brush that is applied to the text contents. The default is a SolidColorBrush with Color value Black.

Dependency property identifier field: ForegroundProperty

The Foreground property specifies a Brush for the rendered text. A Brush can represent a solid color, a linear or radial gradient, or an image.

Some brush types (SolidColorBrush) support a XAML attribute syntax, whereas other brush types (ImageBrush, LinearGradientBrush, and RadialGradientBrush) support only an object element syntax. This is why two versions of XAML syntax are shown for this property.

When animating a Foreground, you must use indirect targeting. For instance, if you are animating the color of a SolidColorBrush that is the Foreground of a TextBlock, the syntax would be <ColorAnimation ... Storyboard.TargetProperty="(Run.Foreground).(SolidColorBrush.Color)" />.

XAML property element usage for a non-solid brush is uncommon, because it clashes with the inherent document object model intention for text elements. If you use a non-solid brush, you might instead make a resource reference to a ResourceDictionary defined brush.

Windows Phone OS

Supported in: 8.1, 8.0, 7.1

Windows Phone

Show:
© 2018 Microsoft