This documentation is archived and is not being maintained.

DrawingGroup.Opacity Property

Gets or sets the opacity of this DrawingGroup. This is a dependency property.

Namespace: System.Windows.Media
Assembly: PresentationCore (in presentationcore.dll)
XML Namespace:

public double Opacity { get; set; }
/** @property */
public double get_Opacity ()

/** @property */
public void set_Opacity (double value)

public function get Opacity () : double

public function set Opacity (value : double)

<object Opacity="double" .../>

Property Value

A value between 0 and 1, inclusive, that describes the opacity of this DrawingGroup. A value of 1 specifies that the DrawingGroup is completely opaque; a value of 0 specifies that it is completely transparent. A value that is less than 0 is treated as 0; and a value that is larger than 1 is treated as 1. The default value is 1.

Identifier Field


Metadata Flags


Another way to control the opacity of a GeometryDrawing is to specify the Opacity of its Brush.

DrawingGroup operations are applied in the following order:

  1. OpacityMask

  2. Opacity

  3. BitmapEffect

  4. ClipGeometry

  5. GuidelineSet

  6. Transform

This example shows how to modify the opacity of a Drawing. The DrawingGroup class is the only type of Drawing object that has an Opacity property.

To change the opacity of a Drawing object, add it to a DrawingGroup and set the Opacity property of the DrawingGroup object.

The Opacity setting of the DrawingGroup object is multiplied by the opacity of its child drawings; for example, if a DrawingGroup has an Opacity of 0.5 and it contains a GeometryDrawing that has a 50 percent opaque Brush, the brush is 25 percent opaque (0.5 * 0.5).

To alter the opacity of select portions of a drawing, use an OpacityMask.

The following example uses a DrawingGroup to combine several GeometryDrawing objects. The example also sets the opacity of the DrawingGroup object to 0.25 so that the drawings are 25 percent opaque.

The following illustration shows the output that the example produces. The illustration shows the DrawingGroup before and after its Opacity is set to 0.25.

DrawingGroups with different opacity settings
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SDKSample
    public class OpacityExample : Page
        public OpacityExample()

            // Create a GeometryDrawing.

            // Define the drawing's contents.
            PathFigure pLineFigure = new PathFigure();
            pLineFigure.StartPoint = new Point(25, 25);
            PolyLineSegment pLineSegment = new PolyLineSegment();
            pLineSegment.Points.Add(new Point(0, 50));
            pLineSegment.Points.Add(new Point(25, 75));
            pLineSegment.Points.Add(new Point(50, 50));
            pLineSegment.Points.Add(new Point(25, 25));
            pLineSegment.Points.Add(new Point(25, 0));
            PathGeometry pGeometry = new PathGeometry();

            GeometryDrawing drawing1 = new GeometryDrawing(
                    new Pen(Brushes.Black, 10),

            // Create another GeometryDrawing.
            GeometryDrawing drawing2 = new GeometryDrawing(
                    new Pen(Brushes.Black, 2),
                    new EllipseGeometry(new Point(10, 10), 5, 5)

            // Create the DrawingGroup and add the
            // geometry drawings.
            DrawingGroup aDrawingGroup = new DrawingGroup();

            // Set the opacity of the DrawingGroup to 0.25.
            aDrawingGroup.Opacity = 0.25;

            // Use an Image control and a DrawingImage to
            // display the drawing.
            DrawingImage aDrawingImage = new DrawingImage(aDrawingGroup);

            // Freeze the DrawingImage for performance benefits.

            Image anImage = new Image();
            anImage.Source = aDrawingImage;
            anImage.Stretch = Stretch.None;
            anImage.HorizontalAlignment = HorizontalAlignment.Left;

            // Create a border around the images and add it to the
            // page.
            Border imageBorder = new Border();
            imageBorder.BorderBrush = Brushes.Gray;
            imageBorder.BorderThickness = new Thickness(1);
            imageBorder.VerticalAlignment = VerticalAlignment.Top;
            imageBorder.HorizontalAlignment = HorizontalAlignment.Left;
            imageBorder.Margin = new Thickness(20);
            imageBorder.Child = anImage;

            this.Background = Brushes.White;
            this.Margin = new Thickness(20);
            this.Content = imageBorder;


  Background="White" Margin="20">
  <Border BorderBrush="Gray" BorderThickness="1" 
    HorizontalAlignment="Left" VerticalAlignment="Top"
    <Image Stretch="None">
        <DrawingImage PresentationOptions:Freeze="True">

            <!-- The drawing group, with an Opacity of 0.25. -->
            <DrawingGroup Opacity="0.25">
              <GeometryDrawing Brush="Lime" Geometry="M 25,25 L 0,50 25,75 50,50 25,25 25,0">
                  <Pen Thickness="10" Brush="Black" />
              <GeometryDrawing Brush="Lime">
                  <EllipseGeometry Center="10,10" RadiusX="5" RadiusY="5" />
                  <Pen Thickness="2" Brush="Black" />


Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0