Basic Drawing and Shapes in Windows Presentation Foundation
This
article covers the new features introduced in Windows Presentation Foundation
for drawing shapes. A Shape is a type of UIElement, and enables you to draw a
shape to the screen. The Content Panels can contain Shape elements as children.
Whenever the properties of these elements got changed, screen reflects those changes
automatically.
Shape Objects
WPF
provides number of Shape classes. These are derived from Shape class. Ellipse,
Line, Path, Polygon, Polyline, and Rectangle are few classes derived from Shape
class. The WPF also defines 3DGementric shapes. The user can define any 3D shape
by specifying collection triangular surfaces in 3D space.
Shape
class has following properties:
Stroke - StrokeThickness - Fill - Data
->>
Stretch : Specify the behavior of the shapes, when the width and height of Parent
element got changed. The following are values 'Stretch' property : None
- Fill - Uniform - UniformToFill
->>
Transformation : Specify the type and measure for transformation
RotateTransform
- Centre, Angle ScaleTransform - Origin, scale factor SkewTransform - Tilting
angle TranslateTransform - Displacement in x and y
Example:
The
example below defines a line and polyline elements with a stretch to fill and
10 deg rotation.
The
result of the above code will give you an image as shown below:
Thus
you can use the shape object to draw the shapes. You can access the different
graphics and rendering services that are available in the Windows Presentation
Foundation (WPF).