Freigeben über


TextElement.Foreground Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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

Namespace:  System.Windows.Documents
Assembly:  System.Windows (in System.Windows.dll)

Syntax

'Declaration
Public Property Foreground As Brush
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 Silverlight 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.

Remarks

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.

Version Information

Silverlight

Supported in: 5, 4

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.