Classes that derive from this abstract base class define geometric shapes. objects can be used for clipping, hit-testing, and rendering 2-D graphic data.
Assembly: PresentationCore (in PresentationCore.dll)
Geometry Compared to Shape
The System.Windows.Shapes.Shape class has a Fill, Stroke, and other rendering properties that and its derived classes lack. The Shape class is a FrameworkElement and therefore participates in the layout system; its derived classes can be used as the content of any element that supports UIElement children.
The class, on the other hand, simply defines the geometry of a shape, and cannot render itself. Because of its simplicity, it has a wider range of uses.
Freezable Features: Because it inherits from the Freezable class, the class provides several special features: objects can be declared as resources, shared among multiple objects, made read-only to improve performance, cloned, and made thread-safe. For more information about the different features provided by Freezable objects, see Freezable Objects Overview.
Although this class is abstract, it is not publicly extensible.
This example shows how to create composite shapes using 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 How to: Create a Shape by Using a PathGeometry. Although this example renders a shape to the screen using a Path element, 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: Create a Shape by Using a PathGeometry||This example shows how to create a shape using the PathGeometry class. PathGeometry objects are composed of one or more PathFigure objects; each PathFigure represents a different "figure" or shape. Each PathFigure is itself composed of one or more PathSegment objects, each representing a connected portion of the figure or shape. Segment types include LineSegment, ArcSegment, and BezierSegment.|
|How to: Animate an EllipseGeometry||This example shows how to animate a within a Path element. In the following example, a PointAnimation is used to animate the Center of an EllipseGeometry.|
Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.