Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

CombinedGeometry Class

Represents a 2-D geometric shape defined by the combination of two Geometry objects.

Namespace: System.Windows.Media
Assembly: PresentationCore (in presentationcore.dll)
XML Namespace:  http://schemas.microsoft.com/winfx/2006/xaml/presentation

public sealed class CombinedGeometry : Geometry
public final class CombinedGeometry extends Geometry
public final class CombinedGeometry extends Geometry
<CombinedGeometry .../>

The GeometryCombineMode property specifies how the two geometries will be combined. Note that CombinedGeometry combines the area specified by two geometries, so geometries that do not have area (such as LineGeometry) disappear when combined.

Geometries can be combined in several ways: using a GeometryGroup, a CombinedGeometry, or the Combine method of the Geometry class.

  • A GeometryGroup creates a composite geometry from one or more Geometry objects.

  • A CombinedGeometry uses a specified boolean operation to combine the area described by two Geometry objects.

  • The static Combine method of the Geometry class behaves in exactly the same manner as the CombinedGeometry object.

Careful thought should be involved when using a CombinedGeometry to perform a union as it can be very CPU-expensive. In most cases, a GeometryGroup or AddGeometry will work better.

Use a CombinedGeometry only when any of the following apply:

  • The geometric operation is not a union.

  • Either of the geometries have a FillRule value of EvenOdd and the geometries are self-intersecting (i.e. the FillRule actually matters).

  • Time is not a concern, but space is (for instance, if the geometry is created once and then cached). Typically, CombinedGeometry produces smaller output than AddGeometry.

  • The resulting geometry will be stroked or used in a path animation and AddGeometry does not provide the desired outline.

Freezable Features

A CombinedGeometry is a type of Freezable object. For information about Freezable features, such as freezing and cloning, see the Freezable Objects Overview.

This example shows how to combine geometries. To combine two geometries, use a CombinedGeometry object. Set its Geometry1 and Geometry2 properties with the two geometries to combine, and set the GeometryCombineMode property, which determines how the geometries will be combined together, to Union, Intersect, Exclude, or Xor.

To create a composite geometry from two or more geometries, use a GeometryGroup.

In the following example, a CombinedGeometry is defined with a geometry combine mode of Exclude. Both Geometry1 and the Geometry2 are defined as circles of the same radius, but with centers offset by 50.

<Path Stroke="Black" StrokeThickness="1" Fill="#CCCCFF">
  <Path.Data>
    
    <!-- Combines two geometries using the exclude combine mode. -->
    <CombinedGeometry GeometryCombineMode="Exclude">
      <CombinedGeometry.Geometry1>
        <EllipseGeometry RadiusX="50" RadiusY="50" Center="75,75" />
      </CombinedGeometry.Geometry1>
      <CombinedGeometry.Geometry2>
        <EllipseGeometry RadiusX="50" RadiusY="50" Center="125,75" />
      </CombinedGeometry.Geometry2>
    </CombinedGeometry>
  </Path.Data>
</Path>

Combined Geometry Exclude


Results of the Exclude combine mode

In the following markup, a CombinedGeometry is defined with a combine mode of Intersect. Both Geometry1 and the Geometry2 are defined as circles of the same radius, but with centers offset by 50.

<Path Stroke="Black" StrokeThickness="1" Fill="#CCCCFF">
  <Path.Data>
    
    <!-- Combines two geometries using the intersect combine mode. -->
    <CombinedGeometry GeometryCombineMode="Intersect">
      <CombinedGeometry.Geometry1>
        <EllipseGeometry RadiusX="50" RadiusY="50" Center="75,75" />
      </CombinedGeometry.Geometry1>
      <CombinedGeometry.Geometry2>
        <EllipseGeometry RadiusX="50" RadiusY="50" Center="125,75" />
      </CombinedGeometry.Geometry2>
    </CombinedGeometry>
  </Path.Data>
</Path>

Combined Geometry Intersect


Results of the Intersect combine mode

In the following markup, a CombinedGeometry is defined with a combine mode of Union. Both Geometry1 and the Geometry2 are defined as circles of the same radius, but with centers offset by 50.

<Path Stroke="Black" StrokeThickness="1" Fill="#CCCCFF">
  <Path.Data>
    
    <!-- Combines two geometries using the union combine mode. -->
    <CombinedGeometry GeometryCombineMode="Union">
      <CombinedGeometry.Geometry1>
        <EllipseGeometry RadiusX="50" RadiusY="50" Center="75,75" />
      </CombinedGeometry.Geometry1>
      <CombinedGeometry.Geometry2>
        <EllipseGeometry RadiusX="50" RadiusY="50" Center="125,75" />
      </CombinedGeometry.Geometry2>
    </CombinedGeometry>
  </Path.Data>
</Path>

Combined Geometry Union


Results of the Union combine mode

In the following markup, a CombinedGeometry is defined with a combine mode of Xor. Both Geometry1 and the Geometry2 are defined as circles of the same radius, but with centers offset by 50.

<Path Stroke="Black" StrokeThickness="1" Fill="#CCCCFF">
  <Path.Data>
    
    <!-- Combines two geometries using the XOR combine mode. -->
    <CombinedGeometry GeometryCombineMode="Xor">
      <CombinedGeometry.Geometry1>
        <EllipseGeometry RadiusX="50" RadiusY="50" Center="75,75" />
      </CombinedGeometry.Geometry1>
      <CombinedGeometry.Geometry2>
        <EllipseGeometry RadiusX="50" RadiusY="50" Center="125,75" />
      </CombinedGeometry.Geometry2>
    </CombinedGeometry>
  </Path.Data>
</Path>

Combined Geometry Xor


Results of the Xor combine mode

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

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
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft