August 2012
Intermediate to advanced
840 pages
22h 41m
English
Any WPF control can display an image. Example program FormImage, which is available for download on the book’s website, uses the following XAML code to fill a Grid control’s background:
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml
Title="FormImage" Height="300" Width="300">
<Window.Resources>
<ImageBrush ImageSource="smile.bmp" x:Key="brSmile" />
</Window.Resources>
<Grid Background="{StaticResource brSmile}">
</Grid>
</Window>
Although a Grid control can display an image or other graphic, its real purpose is to arrange other controls. The following table describes controls whose main purpose is to present graphics and media.
| CONTROL | PURPOSE |
| Ellipse | Displays an ellipse. |
| Image | Displays a bitmap image, for example, from a .bmp, .jpg, or .png file. Can optionally stretch the image with or without distortion. |
| Line | Draws a line segment. |
| MediaElement | Presents audio and video. To let you control the media, it provides Play, Pause, and Stop methods, and Volume and SpeedRatio properties. (See example program UseMediaElement, available for download on the book’s website.) |
| Path | Draws a series of drawing instructions. |
| Polygon | Draws a closed polygon. |
| Polyline | Draws a series of connected line segments. |
| Rectangle | Draws a rectangle, optionally with rounded corners. |
The shape drawing objects (Ellipse, Line, Path, Polygon, Polyline, and Rectangle) ...
Read now
Unlock full access