Ler em inglês Editar

Compartilhar via


Control.Foreground Property

Definition

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 a brush that describes the foreground color.

C#
[System.ComponentModel.Bindable(true)]
public System.Windows.Media.Brush Foreground { get; set; }

Property Value

The brush that paints the foreground of the control. The default value is the system dialog font color.

Attributes

Examples

The following example shows how to set the font style property of a control.

XAML
<Button Name="btn1" Foreground="Black" 
        Click="ChangeForeground">
  Foreground
</Button>
C#
void ChangeForeground(object sender, RoutedEventArgs e)
{
    if (btn1.Foreground == Brushes.Green)
    {
        btn1.Foreground = Brushes.Black;
        btn1.Content = "Foreground";
    }
    else
    {
        btn1.Foreground = Brushes.Green;
        btn1.Content = "Control foreground(text) changes from black to green.";
    }
}

Remarks

This property only affects a control whose template uses the Foreground property as a parameter. On other controls, this property has no impact.

Dependency Property Information

Item Value
Identifier field ForegroundProperty
Metadata properties set to true AffectsRender, SubPropertiesDoNotAffectRender, Inherits

Applies to

Produto Versões
.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, 10