Export (0) Print
Expand All
0 out of 1 rated this helpful - Rate this topic

Geometry Class

Classes that derive from this abstract base class define geometric shapes. Geometry objects can be used for clipping, hit-testing, and rendering 2-D graphic data.

Namespace: System.Windows.Media
Assembly: PresentationCore (in presentationcore.dll)

[LocalizabilityAttribute(LocalizationCategory.None, Readability=Readability.Unreadable)] 
public abstract class Geometry : Animatable, IFormattable
/** @attribute LocalizabilityAttribute(LocalizationCategory.None, Readability=Readability.Unreadable) */ 
/** @attribute TypeConverterAttribute(System.Windows.Media.GeometryConverter) */ 
public abstract class Geometry extends Animatable implements IFormattable
LocalizabilityAttribute(LocalizationCategory.None, Readability=Readability.Unreadable) 
public abstract class Geometry extends Animatable implements IFormattable

Geometry Compared to Shape



Freezable Features: Because it inherits from the Freezable class, the Geometry class provides several special features: Geometry 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 the Freezable Objects Overview.

Notes to Inheritors: Although this class is abstract, it is not publicly extensible.


<!-- Displays the geometry. --> 
<Path Stroke="Black" StrokeThickness="1" Fill="#CCCCFF">
    <!-- 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" />

// 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();

myPath.Data = myGeometryGroup;

// Add path shape to the UI.
StackPanel mainPanel = new StackPanel();
this.Content = mainPanel;

The following illustration shows the shape created in the previous example.

Composite Geometry

A composite geometry created using a GeometryGroup

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.


More Code

How to: Create a Shape by Using a PathGeometry


How to: Animate an EllipseGeometry

This example shows how to animate a Geometry within a Path element. In the following example, a PointAnimation is used to animate the Center of an EllipseGeometry.

             Derived Classes



.NET Framework

Supported in: 3.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2014 Microsoft. All rights reserved.