更新:2007 年 11 月
获取或设置一个用于描述前景色的画笔。这是一个依赖项属性。
命名空间:
System.Windows.Controls 程序集:
PresentationFramework(在 PresentationFramework.dll 中)
<BindableAttribute(True)> _
Public Property Foreground As Brush
Dim instance As Control
Dim value As Brush
value = instance.Foreground
instance.Foreground = value
[BindableAttribute(true)]
public Brush Foreground { get; set; }
[BindableAttribute(true)]
public:
property Brush^ Foreground {
Brush^ get ();
void set (Brush^ value);
}
/** @property */
/** @attribute BindableAttribute(true) */
public Brush get_Foreground()
/** @property */
/** @attribute BindableAttribute(true) */
public void set_Foreground(Brush value)
public function get Foreground () : Brush
public function set Foreground (value : Brush)
此属性仅影响其模板使用 Foreground 属性作为参数的控件。对于其他控件,此属性不会产生任何影响。
下面的示例演示如何设置控件的字体样式属性。
<Button Name="btn1" Foreground="Black"
Click="ChangeForeground">
Foreground
</Button>
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
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.";
}
}
Windows Vista
.NET Framework 和 .NET Compact Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求。
.NET Framework
受以下版本支持:3.5、3.0
参考
其他资源