다음을 통해 공유


GradientStops (LinearGradientBrush)

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

Gets or sets the collection of gradient stops for a LinearGradientBrush object.

<LinearGradientBrush ...>
  oneOrMoreGradientStops
</LinearGradientBrush>
value = object.GradientStops
object.GradientStops = value

XAML Values

Value

Description

oneOrMoreGradientStops

One or more GradientStop object elements.

Property Value

Type: GradientStopCollection

A collection of the GradientStop objects that are 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.

Managed Equivalent

GradientStops

Remarks

The XAML syntax for GradientStops is an example of an implicit collection syntax, where you can omit the GradientStopCollection object element and the <LinearGradientBrush.GradientStops> property element. Instead, you generally include one or more GradientStop object elements as child elements of a LinearGradientBrush. Explicitly including a GradientStopCollection object element is permissible in 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.

Example

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

<Canvas
  xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation"
  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