共用方式為


Fill (Shape)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets or sets the Brush that specifies how to paint the interior of the shape.

<object Fill="colorString"  .../>
-or-
<object>
  <object.Fill>
    singleBrush
  </object.Fill>
</object>
value = object.Fill
object.Fill = value

XAML Values

Value

Description

colorString

The Color for a SolidColorBrush expressed as an attribute string. This can be a named color, an RGB value, or an ScRGB value. RGB or ScRGB may also specify alpha information. See the "colorString Grammar" section of the Color reference topic.

singleBrush

Within opening and closing property elements for object.Fill, exactly one object element for an object that derives from Brush. The object element can be one of the following: LinearGradientBrush, RadialGradientBrush, ImageBrush, SolidColorBrush, VideoBrush.

Property Value

Type: Brush

The Brush that describes how the interior of the shape is painted.

This property is read/write. The default value is null (see the "Remarks" section).

Managed Equivalent

Fill

Remarks

For rendering, the null default value is interpreted as a Brush that has no color value but renders as Transparent. A value of a null Brush has no region that can be hit tested, while a value of an actual brush with a color value of Transparent can be hit tested.

If you are setting this property in script, the most common technique is to use the colorString grammar to specify the value as a string. Alternatively, you might set the value to an object such as LinearGradientBrush, by specifying the XAML that defines the brush as the input for CreateFromXaml and setting Fill to the CreateFromXAML output.

Setting the Fill for a line (Line or Polyline) has no effect, because a line has no interior. Instead, use the Stroke and StrokeThickness properties for lines.

Some brush types (SolidColorBrush) support a XAML attribute syntax, whereas other brush types (ImageBrush, LinearGradientBrush, and RadialGradientBrush) support only an object element syntax. This is why two versions of XAML syntax are shown for this property.

When animating a Fill, you must use indirect targeting. For example, if you are animating the color of a SolidColorBrush that is the Fill of a Rectangle, the syntax would be <ColorAnimation ... Storyboard.TargetProperty="(Rectangle.Fill).(SolidColorBrush.Color)" />.

The area where the Fill applies to a Path is potentially influenced by its geometry data's FillRule.

If a Fill is null (or not specified), there is no region that can be hit tested within the object.