Control.Foreground Control.Foreground Control.Foreground Control.Foreground Property

定義

取得或設定描述前景色彩的筆刷。Gets or sets a brush that describes the foreground color.

public:
 property System::Windows::Media::Brush ^ Foreground { System::Windows::Media::Brush ^ get(); void set(System::Windows::Media::Brush ^ value); };
[System.ComponentModel.Bindable(true)]
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 that paints the foreground of the control. 預設值為系統對話方塊字型的色彩。The default value is the system dialog font color.

範例

下列範例顯示如何設定控制項的字型樣式屬性。The following example shows how to set the font style property of a control.

<Button Name="btn1" Foreground="Black" 
        Click="ChangeForeground">
  Foreground
</Button>
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.";
    }
}
Private Sub ChangeForeground(ByVal Sender As Object, ByVal e As RoutedEventArgs)

    If (Equals(btn1.Foreground, Brushes.Green)) Then

        btn1.Foreground = Brushes.Black
        btn1.Content = "Foreground"

    Else

        btn1.Foreground = Brushes.Green
        btn1.Content = "Control foreground(text) changes from black to green."
    End If
End Sub

備註

此屬性只會影響其範本使用Foreground屬性做為參數的控制項。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

識別碼欄位Identifier field ForegroundProperty
中繼資料屬性設定為trueMetadata properties set to true AffectsRenderSubPropertiesDoNotAffectRenderInheritsAffectsRender, SubPropertiesDoNotAffectRender, Inherits

適用於