LinearShade Class

LinearShade Class - Linear Gradient Shading for Word Documents

Namespace: Vega.DOM
Inheritance: BaseGraphicElement → LinearShade
Implements: ILinearShade, IBaseGraphicElement

Master linear gradient shading in Word documents using VDocs LinearShade API. Control the angle and scaling behaviour of linear gradients, enabling precise directional color transitions for text and objects programmatically in C#.

The LinearShade class controls the direction and scaling of a linear gradient fill. It is a component of the Gradient class, used when you want a smooth color transition along a straight line. The angle is specified via the Rotation type, which automatically normalises values to the range [0, 360). The Scaled property determines whether the gradient is adjusted to the object's dimensions or remains at a fixed size.

Constructors

LinearShade()
Default Constructor

Creates a new linear shade instance with Angle initialised to null and Scaled set to false. Set properties after creation.

Properties

Property Type Description
Angle Rotation? Direction of the linear gradient, measured in degrees. 0° is left‑to‑right, 90° is top‑to‑bottom. Values are normalised to 0‑360.
Scaled bool If true, the gradient is scaled to fit the object's bounding box. If false, the gradient uses absolute dimensions and may appear differently if the object is resized.

Namespace: Vega.DOM

Inheritance: BaseElement → Rotation

Implements: IRotation

Description: Represents a rotation angle in degrees, automatically normalised to the range [0, 360).

Key member:

  • double Value – The normalised angle.
  • implicit operator Rotation(double) – Converts a double to a Rotation with normalisation.

Example: Rotation angle = 450; // becomes 90

Full Rotation documentation →

Code Examples

Setting a Linear Shade with Angle

// Create a linear shade with a 45° angle and scaling enabled
var linearShade = new LinearShade
{
    Angle = 45,          // implicitly converted to Rotation (normalised)
    Scaled = true
};

// Use in a gradient
var gradient = new Gradient
{
    GradientStops = new List<IGradientStop>
    {
        new GradientStop { StopColor = Color.Red, StopPosition = 0 },
        new GradientStop { StopColor = Color.Blue, StopPosition = 100 }
    },
    LinearShade = linearShade
};

Using Rotation Explicitly

// Create a Rotation instance for 270° (which is same as -90°)
var rotation = new Rotation { Value = 270 };

var linearShade = new LinearShade
{
    Angle = rotation,
    Scaled = false
};

Applying to Text via Gradient Fill

var gradient = new Gradient
{
    GradientStops = new List<IGradientStop>
    {
        new GradientStop { StopColor = Color.Gold, StopPosition = 0 },
        new GradientStop { StopColor = Color.DarkOrange, StopPosition = 100 }
    },
    LinearShade = new LinearShade
    {
        Angle = 135,   // diagonal from bottom‑left to top‑right
        Scaled = true
    }
};

var textEffect = new TextEffect
{
    GradientFill = gradient
};

var textStyle = new TextStyle
{
    Font = new Font { Latin = new FontPart { FontName = "Arial", Size = 48 } },
    TextEffect = textEffect
};

Best Practices

Set Angle for Desired Direction

Use 0° for left‑to‑right, 90° for top‑to‑bottom, 180° for right‑to‑left, and 270° for bottom‑to‑top. Diagonal angles like 45° create smooth corner‑to‑corner transitions.

Scaled vs Unscaled

Use Scaled = true when the gradient should always stretch to fill the object, regardless of its size. Use false when you want the gradient's proportions to remain constant (e.g., for a consistent pattern).

Leverage Rotation Normalisation

You can assign any angle (e.g., 450, -90) and it will be normalised. This is useful when calculating angles programmatically.

Performance Tip: Linear shades are computationally inexpensive. The main cost comes from the number of gradient stops.
Compatibility Note: Linear gradients are supported in Word 2007 and later. Scaling behaviour may differ slightly between versions.

Common Use Cases & Search Terms

Developers searching for these solutions will find this page helpful:

  • "Linear gradient angle C#" – Control direction with Angle
  • "Gradient scaling Word C#"Scaled property
  • "Rotation class VDocs" – Normalised angle values
  • "Set gradient direction C#" – Using LinearShade in Gradient
  • "Gradient fill text C#" – Apply via TextEffect

Frequently Asked Questions

What does the Angle value mean?

Angle specifies the direction of the linear gradient. 0° is from left to right, 90° from top to bottom, 180° from right to left, and 270° from bottom to top. Any angle can be used; it is normalised to 0‑360°.

What is the effect of Scaled = false?

When Scaled = false, the gradient is not stretched to the object's bounding box. Instead, it maintains its absolute proportions. If the object is larger, the gradient may repeat or be clipped depending on the implementation.

Can I use negative angles?

Yes, negative angles are accepted and will be normalised to the equivalent positive angle. For example, -90° becomes 270°.

How do I apply a linear shade to text?

Create a Gradient, set its LinearShade property, then assign the gradient to a TextEffect.GradientFill, and finally attach the TextEffect to a TextStyle.

We use cookies to improve your experience.