How to: Create a Combined Geometry
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.
Example
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
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
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
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