Most of the classes in WPF's drawing toolkit fall into one of three categories: shapes, brushes, and pens. There are many variations on these themes, and we will examine them in detail later. However, to get anywhere at all with graphics, we need a basic understanding.
Shapes are objects in the user interface tree that provide the basic building blocks for drawing. The Ellipse, Path, and Rectangle elements we have seen already are all examples of shape objects. There is also support for lines, both single- and multisegment, using Line and Polyline, respectively. Polygon creates closed shapes whose edges are all straight. The Path class supports both open and closed shapes with any mixture of straight and curved edges. Figure 13-8 shows each of these shapes in action.
Figure 13-8. Rectangle, Ellipse, Line, Polyline, Polygon, and Path
Regardless of which shape you choose, you'll need to decide how it should be colored in. For this, you use a brush. Many brush types are available. The simplest is the single-color SolidColorBrush. You can achieve more interesting visual effects using the LinearGradientBrush or RadialGradientBrush. These allow the color to change over the surface of a shape, which can be a great way of providing an impression of depth. You can also create brushes based on images—the ImageBrush uses a bitmap, and the DrawingBrush uses a scalable drawing. Finally, the VisualBrush lets you take any visual tree—any chunk of user interface you like—and use that as a brush to paint some other shape. This makes it easy to achieve effects such as reflections of whole sections of your user interface, or wrapping a user interface around a 3D model.
Finally, pens are used to draw the outline of a shape. A pen is really just an augmented brush. When you create a Pen object, you give it a Brush to tell it how it should paint onto the screen. The Pen class just adds information like line thickness, dash patterns, and end cap details. Figure 13-9 shows a few of the effects available using brushes and pens.
Was this article helpful?
What you need to know about… Project Management Made Easy! Project management consists of more than just a large building project and can encompass small projects as well. No matter what the size of your project, you need to have some sort of project management. How you manage your project has everything to do with its outcome.