Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

RectangleGeometry Class

Describes a two-dimensional rectangle.

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

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

This example describes how to use the RectangleGeometry class to describe a rectangle.

The following example shows how to create and render a RectangleGeometry. The relative position and the dimensions of the rectangle are defined by a Rect structure. The relative position is 50,50 and the height and the width are both 25 creating a square. The rectangle's interior is painted with a LemonChiffon brush and its outline is painted with a Black stroke with a thickness of 1.

<Path Fill="LemonChiffon" Stroke="Black" StrokeThickness="1">
  <Path.Data>
    <RectangleGeometry Rect="50,50,25,25" />
  </Path.Data>
</Path>

RectangleGeometry myRectangleGeometry = new RectangleGeometry();    
myRectangleGeometry.Rect = new Rect(50,50,25,25);

Path myPath = new Path();
myPath.Fill = Brushes.LemonChiffon;
myPath.Stroke = Brushes.Black;
myPath.StrokeThickness = 1;
myPath.Data = myRectangleGeometry;

RectangleGeometry


A RectangleGeometry

Although this example used a Path element to render the RectangleGeometry, there are many other ways to use RectangleGeometry objects. For example, a RectangleGeometry can be used to specify the Clip of a UIElement or the Geometry of a GeometryDrawing.

Other simple geometry classes include LineGeometry and EllipseGeometry. These geometries, as well as more complex ones, can also be created using a PathGeometry or StreamGeometry.

More Code

How to: Round the Corners of a RectangleGeometry

To round the corners of a RectangleGeometry, set its RadiusX and RadiusY properties to a value greater than zero. The larger the values, the rounder the rectangle's corners.

How to: Animate a Rectangle Geometry by Using Key Frames

This example shows how to animate the Rect property of a RectangleGeometry by using key frames.

How to: Create a Composite Shape

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.

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.

System.Object
   System.Windows.Threading.DispatcherObject
     System.Windows.DependencyObject
       System.Windows.Freezable
         System.Windows.Media.Animation.Animatable
           System.Windows.Media.Geometry
            System.Windows.Media.RectangleGeometry
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
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.