Control.Foreground 属性

定义

获取或设置一个用于描述前景色的画笔。

public:
 property Brush ^ Foreground { Brush ^ get(); void set(Brush ^ value); };
Brush Foreground();

void Foreground(Brush value);
public Brush Foreground { get; set; }
var brush = control.foreground;
control.foreground = brush;
Public Property Foreground As Brush
<control Foreground="{StaticResource resourceName}"/>
- or -
<control Foreground="colorString"/>
- or -
<control>
  <control.Foreground>singleBrush</control.Foreground>
</control>

属性值

用于绘制控件的前景的画笔。 默认值为颜色为黑色SolidColorBrush

注解

每个控件可能基于其可视模板以不同的方式应用此属性。 此属性仅影响其模板使用 Foreground 属性作为参数的控件。 在其他控件上,此属性不起作用。 通常,ContentControl 派生控件使用 {TemplateBinding} 标记扩展将其前台值绑定到控件模板中 ContentPresenter的前景。 同一颜色/画笔还可用于模板中其他装饰元素的值, (字形、图标、控件表面) 或组合部件属性(如 TimePicker 控件的各个 ComboBox 元素)。 有关视觉对象模板和控件模板化的详细信息,请参阅 Template 属性的控件样式设置或参考页。

从 Windows 10 版本 1607 (Windows 软件开发工具包 (SDK) 版本 10.0.14393.0) 开始,generic.xaml 包含可用于在不修改控件模板的情况下修改不同视觉状态控件颜色的资源。 在面向此软件开发工具包 (SDK) 或更高版本的应用中,修改这些资源优先于设置 Background、Foreground 和 BorderBrush 等属性。 有关详细信息,请参阅 XAML 样式一文的轻量级样式部分。

适用于

另请参阅