The following image shows the rendered shape.įor more information about PathGeometry and the other Geometry classes, see the Geometry Overview. In the following example, a Path is used to draw a quadratic Bezier curve. Segment types include the following: LineSegment, BezierSegment, and ArcSegment. Each PathFigure is itself comprised of one or more PathSegment objects, each representing a connected portion of the figure or shape. PathGeometry objects are comprised of one or more PathFigure objects each PathFigure represents a different "figure" or shape. To create more complex shapes or create curves, use a PathGeometry. The LineGeometry, RectangleGeometry, and EllipseGeometry classes describe relatively simple shapes. There are a variety of Geometry objects to choose from. To use a Path, you create a Geometry and use it to set the Path object's Data property. These curves and shapes are described using Geometry objects. The Path class enables you to draw curves and complex shapes. The following image shows an example of a rendered Ellipse. ' Set the width and height of the Ellipse. MySolidColorBrush.Color = Color.FromArgb(255, 255, 255, 0) ' Describes the brush's color using RGB values. ' Create a SolidColorBrush with a red color to fill theĭim mySolidColorBrush As New SolidColorBrush() ' Create a StackPanel to contain the shape. Partial Public Class SetBackgroundColorOfShapeExample Set the width and height of the Ellipse. Describes the brush's color using RGB values. SolidColorBrush mySolidColorBrush = new SolidColorBrush() Create a SolidColorBrush with a red color to fill the StackPanel myStackPanel = new StackPanel() Create a StackPanel to contain the shape. Public SetBackgroundColorOfShapeExample() Public partial class SetBackgroundColorOfShapeExample : Page To draw a circle, specify an Ellipse whose Width and Height values are equal. Create an Ellipse by defining the shape's Width and Height properties. The following image shows the rendered Line.Īlthough the Line class does provide a Fill property, setting it has no effect because a Line has no area.Īnother common shape is the Ellipse. MyLine.VerticalAlignment = VerticalAlignment.Center MyLine.HorizontalAlignment = HorizontalAlignment.Left MyLine->VerticalAlignment = VerticalAlignment::Center MyLine->HorizontalAlignment = HorizontalAlignment::Left MyLine->Stroke = Brushes::LightSteelBlue The following example shows several ways to specify line coordinates and stroke properties.
The Line class enables you to draw a line between two points. The Canvas panel is a particularly good choice for creating complex drawings because it supports absolute positioning of its child objects. StrokeThickness: Describes the thickness of the shape's outline.įill: Describes how the interior of the shape is painted.ĭata properties to specify coordinates and vertices, measured in device-independent pixels.īecause they derive from UIElement, shape objects can be used inside panels and most controls. Stroke: Describes how the shape's outline is painted. Shape objects share the following common properties. Available shape objects include Ellipse, Line, Path, Polygon, Polyline, and Rectangle. All shape objects inherit from the Shape class. WPF provides a number of ready-to-use Shape objects.
At the top layer, Shape objects are easy to use and provide many useful features, such as layout and participation in the Windows Presentation Foundation (WPF) event system. Windows Presentation Foundation (WPF) offers several layers of access to graphics and rendering services. Because they are UI elements, Shape objects can be used inside Panel elements and most controls. A Shape is a type of UIElement that enables you to draw a shape to the screen.
This topic gives an overview of how to draw with Shape objects.