GradientStops Property

Gets or sets the collection of the brush's gradient stops.

XAML
<LinearGradientBrush ...>
  oneOrMoreGradientStops
</LinearGradientBrush>
-or-
<RadialGradientBrush ...>
  oneOrMoreGradientStops
</RadialGradientBrush>
Scripting
value = object.GradientStops
object.GradientStops = value

Property Value

GradientStopCollection

A collection of the GradientStop objects associated with the brush, each of which specifies a color and an offset along the brush's gradient axis.

This property is read/write. The default value is an empty GradientStopCollection.

Remarks

The XAML syntax for GradientStops is an example of an implicit collection syntax, where you can omit the GradientStopCollection object element, as well as the <object.GradientStops> property element. Instead, you generally include one or more GradientStop object elements as child elements of either a LinearGradientBrush or RadialGradientBrush. For more information about XAML implicit collection syntax, see XAML Syntax Overview. (Explicitly including a DoubleKeyFrameCollection object element is permissible XAML syntax, and might be useful if you intend to name the collection in XAML and manipulate its contents through script later.)

Generally a GradientStopCollection contains a minimum of two gradient stops.

Examples

The following example creates a LinearGradientBrush with four gradient stops in the implicit GradientStopCollection, which is used to paint a Rectangle.

XAML
<Canvas
  xmlns="https://schemas.microsoft.com/client/2007"
  xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml">
  <!-- This rectangle is painted with a diagonal linear gradient. -->
  <Rectangle Width="200" Height="100">
    <Rectangle.Fill>
      <LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
        <GradientStop Color="Yellow" Offset="0.0" />
        <GradientStop Color="Red" Offset="0.25" />
        <GradientStop Color="Blue" Offset="0.75" />
        <GradientStop Color="LimeGreen" Offset="1.0" />
      </LinearGradientBrush>
    </Rectangle.Fill>
  </Rectangle>
</Canvas>

Applies To

LinearGradientBrush, RadialGradientBrush

See Also

Silverlight Brushes Overview