GradientStopCollection class

Contains a collection of GradientStop objects.

To learn more, visit the Working with Graphic Elements documentation article.

public class GradientStopCollection : IEnumerable<GradientStop>


Count { get; }Gets an integer value indicating the number of items in the collection.
Item { get; set; }Gets or sets a GradientStop object in the collection.


Add(GradientStop)Adds a specified GradientStop to a gradient.
GetEnumerator()Returns an enumerator that iterates through the collection.
Insert(int, GradientStop)Inserts a GradientStop to the collection at a specified index.
Remove(GradientStop)Removes a specified GradientStop from the collection.
RemoveAt(int)Removes a GradientStop from the collection at a specified index.


You do not create instances of this class directly. Use the GradientStops property to access gradient stops of fill objects.


Shows how to add gradient stops to the gradient fill.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

Shape shape = builder.InsertShape(ShapeType.Rectangle, 80, 80);
shape.Fill.TwoColorGradient(Color.Green, Color.Red, GradientStyle.Horizontal, GradientVariant.Variant2);

// Get gradient stops collection.
GradientStopCollection gradientStops = shape.Fill.GradientStops;

// Change first gradient stop.            
gradientStops[0].Color = Color.Aqua;            
gradientStops[0].Position = 0.1;
gradientStops[0].Transparency = 0.25;

// Add new gradient stop to the end of collection.
GradientStop gradientStop = new GradientStop(Color.Brown, 0.5);

// Remove gradient stop at index 1.
// And insert new gradient stop at the same index 1.
gradientStops.Insert(1, new GradientStop(Color.Chocolate, 0.75, 0.3));

// Remove last gradient stop in the collection.
gradientStop = gradientStops[2];

Assert.AreEqual(2, gradientStops.Count);

Assert.AreEqual(Color.FromArgb(255, 0, 255, 255), gradientStops[0].BaseColor);
Assert.AreEqual(Color.Aqua.ToArgb(), gradientStops[0].Color.ToArgb());
Assert.AreEqual(0.1d, gradientStops[0].Position, 0.01d);
Assert.AreEqual(0.25d, gradientStops[0].Transparency, 0.01d);

Assert.AreEqual(Color.Chocolate.ToArgb(), gradientStops[1].Color.ToArgb());
Assert.AreEqual(0.75d, gradientStops[1].Position, 0.01d);
Assert.AreEqual(0.3d, gradientStops[1].Transparency, 0.01d);

// Use the compliance option to define the shape using DML
// if you want to get "GradientStops" property after the document saves.
OoxmlSaveOptions saveOptions = new OoxmlSaveOptions { Compliance = OoxmlCompliance.Iso29500_2008_Strict };

doc.Save(ArtifactsDir + "Shape.GradientStops.docx", saveOptions);

See Also