DrawingGroup.ClipGeometry Property


Gets or sets the clip region of this DrawingGroup.

 property System::Windows::Media::Geometry ^ ClipGeometry { System::Windows::Media::Geometry ^ get(); void set(System::Windows::Media::Geometry ^ value); };
public System.Windows.Media.Geometry ClipGeometry { get; set; }
member this.ClipGeometry : System.Windows.Media.Geometry with get, set
Public Property ClipGeometry As Geometry

Property Value


The Geometry that is used to clip this DrawingGroup. The default is null.


This example shows how to define a clip region for a Drawing.

Use a DrawingGroup to define a clip for a Drawing. The DrawingGroup class is the only type of Drawing object that enables you to define your own clip region.

Use a Geometry to describe the clip and apply it to the ClipGeometry property of the DrawingGroup object.

The illustration shows the DrawingGroup before and after the elliptical clip is applied.

DrawingGroup with a defined clip region

The following example uses a DrawingGroup to apply a ClipGeometry to several GeometryDrawing objects.

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SDKSample
    /// <summary>
    /// Shows how to define a clip region for a DrawingGroup.
    /// </summary>
    public class ClipExample : Page
        public ClipExample()

            // Create several GeometryDrawing objects.

            // Create a rectangle.
            GeometryDrawing drawing1 = new GeometryDrawing(
                new RectangleGeometry(new Rect(0,0,50,85))

            // Create a polygon.
            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 drawing2 = new GeometryDrawing(
                    new Pen(Brushes.Black, 10),

            // Create a circle.
            GeometryDrawing drawing3 = 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();

            // Create an EllipseGeometry and use it to
            // clip the DrawingGroup.
            EllipseGeometry clipGeometry = 
                new EllipseGeometry(new Point(25,50), 25, 50);
            aDrawingGroup.ClipGeometry = clipGeometry;

            // 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" HorizontalAlignment="Left">
        <DrawingImage PresentationOptions:Freeze="True">

            <!-- A DrawingGeometry with an elliptical clip region. -->
              <GeometryDrawing Brush="Pink">
                  <RectangleGeometry Rect="0,0,50,85" />
              <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" />

                <EllipseGeometry Center="25,50" RadiusX="25" RadiusY="50" />



Drawings outside the geometry are clipped from the DrawingGroup when it is rendered. The geometry does not have to be rectangular; for example, you can use an EllipseGeometry to clip to an elliptical shape.

DrawingGroup operations are applied in the following order:

  1. OpacityMask

  2. Opacity

  3. BitmapEffect

  4. ClipGeometry

  5. GuidelineSet

  6. Transform

Dependency Property Information

Identifier field ClipGeometryProperty
Metadata properties set to true None

Applies to