Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
Silverlight
Silverlight 3
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Silverlight 3

Other versions are also available for the following:
.NET Framework Class Library for Silverlight
LinearGradientBrush Class

Paints an area with a linear gradient.

Namespace:  System.Windows.Media
Assembly:  System.Windows (in System.Windows.dll)
Visual Basic (Declaration)
Public NotInheritable Class LinearGradientBrush _
    Inherits GradientBrush
Visual Basic (Usage)
Dim instance As LinearGradientBrush
C#
public sealed class LinearGradientBrush : GradientBrush
XAML Implicit Collection Usage
<LinearGradientBrush ...>
  oneOrMoreGradientStops
</LinearGradientBrush

XAML Values

oneOrMoreGradientStops

One or more GradientStop object elements. Object elements defined here become members of the GradientStopCollection when code accesses the GradientStops property at run time.

A LinearGradientBrush paints an area with a linear gradient. A linear gradient defines a gradient along a line. The line's end points are defined by the StartPoint and EndPoint properties of the linear gradient. A LinearGradientBrush brush paints its GradientStops along this line.

The default linear gradient is diagonal. In the default, the StartPoint of a linear gradient is a Point with value 0,0, the upper-left corner of the area being painted, and its EndPoint is a Point with value 1,1, the lower-right corner of the area being painted. The colors in the resulting gradient are interpolated along the diagonal path.

The following illustration shows a diagonal gradient. A line was added to highlight the interpolation path of the gradient from the start point to the end point.

A diagonal linear gradient

ms635198.JOLT_local_726607508_wcpsdk_graphicsmm_diagonalgradientaxis(en-us,VS.95).png

The next illustration shows the same linear gradient, but with highlighted gradient stops.

A diagonal linear gradient with highlighted gradient stops

ms635198.JOLT_local_1860545327_wcpsdk_graphicsmm_4gradientstops(en-us,VS.95).png

It is possible to specify a gradient axis that does not completely fill area being painted. When this occurs, the SpreadMethod property determines how the remaining area is painted.

The following example creates a linear gradient with four colors and uses it to paint a Rectangle.

XAML
<StackPanel>
  <!-- This rectangle is painted with a vertical linear gradient. -->
  <Rectangle Width="200" Height="100">
    <Rectangle.Fill>
      <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,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>
</StackPanel>

The following illustration shows the resulting gradient. The gradient axis is marked with a dashed line, and the gradient stops are marked with circles.

Gradient axis for a vertical gradient

Gradient Stops of Linear Gradient
System..::.Object
  System.Windows..::.DependencyObject
    System.Windows.Media..::.Brush
      System.Windows.Media..::.GradientBrush
        System.Windows.Media..::.LinearGradientBrush
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2010 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker