TextElement.Foreground 属性


获取或设置要应用于元素内容的画笔。Gets or sets the brush to apply to the content of the element.

 property System::Windows::Media::Brush ^ Foreground { System::Windows::Media::Brush ^ get(); void set(System::Windows::Media::Brush ^ value); };
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 used to apply to the text contents. 默认值为 BlackThe default is Black.


下面的示例演示如何 Foreground 使用 Paragraph 作为示例元素来设置特性。The following example shows how to set the Foreground attribute, using Paragraph as the example element.

        This text has a foreground color of dark green, and a background color of bisque.

下图显示了前面的示例的呈现效果。The following figure shows how the preceding example renders.

屏幕快照:前景为绿色,背景为橘黄色Screenshot: Foreground of green, background bisque

下面的示例演示如何以 Foreground 编程方式设置属性。The following example shows how to set the Foreground property programmatically.

Run run = new Run(
    "This text has a foreground color of dark green, and a background color of bisque.");
Paragraph par = new Paragraph(run);

par.Background = Brushes.Bisque;
par.Foreground = Brushes.DarkGreen;
Dim run As New Run("This text has a foreground color of dark green, and a background color of bisque.")
Dim par As New Paragraph(run)

par.Background = Brushes.Bisque
par.Foreground = Brushes.DarkGreen


有关显示可用预定义画笔颜色的样本表,请参阅 BrushesFor a table of swatches that shows the available predefined brush colors, see Brushes.

此依赖属性还具有附加的属性用法。This dependency property also has an attached property usage. 在中 XAMLXAML ,用法为 <object TextElement.Foreground="value".../> ,其中 object 是对象元素, (通常是包含在中的 flow 元素 TextElement) , 是解析为实现值的字符串 BrushIn XAMLXAML, the usage is <object TextElement.Foreground="value".../>, where object is an object element (typically a flow element) contained within a TextElement, and value is a string that resolves to a Brush implementation value. 在代码中,和方法支持附加的属性用法 GetForeground SetForegroundIn code, the attached property usage is supported by the GetForeground and SetForeground methods. 附加的属性用法并不常见,因为可以包含在中的大多数元素都 TextElement 支持类似的非附加 Foreground 属性,内容宿主使用该属性来呈现。The attached property usage is not common, because most elements that can be contained in a TextElement support an analogous nonattached Foreground property, which the content host uses for rendering.

依赖项属性信息Dependency Property Information

标识符字段Identifier field ForegroundProperty
元数据属性设置为 trueMetadata properties set to true AffectsRender, Inherits, SubPropertiesDoNotAffectRenderAffectsRender, Inherits, SubPropertiesDoNotAffectRender