Control.Foreground 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置一个用于描述前景色的画笔。
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; }
[<System.ComponentModel.Bindable(true)>]
member this.Foreground : System.Windows.Media.Brush with get, set
Public Property Foreground As Brush
属性值
用于绘制控件的前景的画笔。 默认值是系统对话框字体颜色。
- 属性
示例
以下示例演示如何设置控件的字体样式属性。
<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 属性作为参数的控件。 在其他控件上,此属性没有影响。
依赖项属性信息
标识符字段 | ForegroundProperty |
元数据属性设置为 true |
AffectsRender, SubPropertiesDoNotAffectRender, Inherits |