Assembly: PresentationCore (in presentationcore.dll)
XML Namespace: http://schemas.microsoft.com/winfx/2006/xaml/presentation
'Declaration <ContentPropertyAttribute("Children")> _ Public NotInheritable Class GeometryGroup Inherits Geometry 'Usage Dim instance As GeometryGroup
/** @attribute ContentPropertyAttribute("Children") */ public final class GeometryGroup extends Geometry
Composite geometry objects can be created using a GeometryGroup, a CombinedGeometry, or by calling the static Geometry method Combine. A CombinedGeometry creates a composite geometry from exactly two geometry objects. A GeometryGroup, on the other hand, creates a composite geometry from any number of geometry objects.
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.
It is worth noting that a GeometryCollection is not itself a composite geometry, but is used by the GeometryGroup class to store Geometry objects.
This example shows how to create composite shapes using Geometry objects and display them using a Path element. In the following example, a LineGeometry, EllipseGeometry, and a RectangleGeometry are used with a GeometryGroup to create a composite shape. The geometries are then drawn using a Path element.
<!-- Displays the geometry. --> <Path Stroke="Black" StrokeThickness="1" Fill="#CCCCFF"> <Path.Data> <!-- Creates a composite shape from three geometries. --> <GeometryGroup FillRule="EvenOdd"> <LineGeometry StartPoint="10,10" EndPoint="50,30" /> <EllipseGeometry Center="40,70" RadiusX="30" RadiusY="30" /> <RectangleGeometry Rect="30,55 100 30" /> </GeometryGroup> </Path.Data> </Path>
// Create a Path to be drawn to the screen. Path myPath = new Path(); myPath.Stroke = Brushes.Black; myPath.StrokeThickness = 1; SolidColorBrush mySolidColorBrush = new SolidColorBrush(); mySolidColorBrush.Color = Color.FromArgb(255, 204, 204, 255); myPath.Fill = mySolidColorBrush; // Create the line geometry to add to the Path LineGeometry myLineGeometry = new LineGeometry(); myLineGeometry.StartPoint = new Point(10, 10); myLineGeometry.EndPoint = new Point(50, 30); // Create the ellipse geometry to add to the Path EllipseGeometry myEllipseGeometry = new EllipseGeometry(); myEllipseGeometry.Center = new Point(40, 70); myEllipseGeometry.RadiusX = 30; myEllipseGeometry.RadiusY = 30; // Create a rectangle geometry to add to the Path RectangleGeometry myRectGeometry = new RectangleGeometry(); myRectGeometry.Rect = new Rect(30, 55, 100, 30); // Add all the geometries to a GeometryGroup. GeometryGroup myGeometryGroup = new GeometryGroup(); myGeometryGroup.Children.Add(myLineGeometry); myGeometryGroup.Children.Add(myEllipseGeometry); myGeometryGroup.Children.Add(myRectGeometry); myPath.Data = myGeometryGroup; // Add path shape to the UI. StackPanel mainPanel = new StackPanel(); mainPanel.Children.Add(myPath); this.Content = mainPanel;
The following illustration shows the shape created in the previous example.
More complex shapes, such as polygons and shapes with curved segments, may be created using a PathGeometry. For an example showing how to create a shape using a PathGeometry, see Create a Shape Using a PathGeometry. Although this example renders a shape to the screen using a Path element, Geometry objects may also be used to describe the contents of a GeometryDrawing or a DrawingContext. They may also be used for clipping and hit-testing.
This example is part of larger sample; for the complete sample, see the Geometries Sample.
|How to: Control the Fill of a Composite Shape|| |
The FillRule property of a GeometryGroup or a PathGeometry, specifies a "rule" which the composite shape uses to determine whether a given point is part of the geometry. There are two possible values for FillRule: EvenOdd and Nonzero. The following sections will describe how to use these two rules.
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 EditionThe Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.