Creating a custom shape
Shapes are (mostly) simple elements deriving from the Shape
abstract base class, which derives directly from FrameworkElement
; shapes providing an inherent graphical representation that can easily be filled, stroked and stretched. Shapes are not controls – they have no template associated with them. They are, however, full elements, providing support for the full range of capabilities, including participation in layout, hit testing, and the multitude of properties and events that make working with these entities as easy as any control.
We can create new shapes by deriving from Shape
, providing a new graphical representation, and taking advantage of the functionality provided by the base Shape
class.
Getting ready
Make sure Visual Studio is up and running.
How to do it...
We'll create a ring shape element, demonstrating the steps necessary to create custom Shape
classes that fit naturally with the rest of WPF, just as the built-in shapes do:
Create a new WPF application...