Working with ready-to-use 2D shapes
In WPF, a Shape
is an UIElement
that enables you to draw a 2D shape in your application. There are a couple of ready-to-use shapes already provided by WPF, and they are as follows:
- Rectangle
- Ellipse
- Line
- Polyline
- Polygon
- Path
All of these UIElements
expose some common properties to draw the shape. The Stroke
and StrokeThickness
properties describe the color and the thickness to draw the shape's outline. The Fill
property describes the color used to decorate the interior of the shape.
In this recipe, we will learn how to create various shapes.
Getting ready
Let's begin with creating a new project. Open your Visual Studio, and create a WPF project called CH02.ShapesDemo
. As we will be creating multiple shapes, we will be using the UniformGrid
panel to host the shapes in this demonstration. You can learn more about this panel in the next chapter.
How to do it...
Follow these steps to create various shapes in your application:
- Open your
MainWindow.xaml
file, and replace...