CHAPTER 1 ■ OVERVIEW OF WPF AND SILVERLIGHT
3
code wrapper around GDI+. Windows Forms, in particular, makes extensive use of this wrapper and this
is one of the key features that differentiates Windows Forms from WPF.
DirectX is an API built for graphically intensive applications, such as Computer Aided Design (CAD)
applications or video games. It provides an interface for rendering graphical scenes represented in three
dimensions onto a two-dimensional projection, such as your computer monitor. Along with OpenGL, it
is the industry standard for developing such applications, and the X in DirectX is itself the inspiration for
the X in XBox, so intrinsically linked are the two.
As managed .NET code can’t use unmanaged APIs directly, WPF uses a wrapper around DirectX as
an intermediary. MIL Core provides a low-level interface to the DirectX API, and WPF builds on top of
this to perform all of its graphical rendering. There are two consequences that arise from all of this: WPF
applications are graphically superior to Windows Forms applications; and WPF applications have a
higher minimum hardware—and, in fact, software—requirement than Windows Forms applications.
Graphically superior means that 3D is supported, cutting-edge graphical rendering techniques can be
employed, and any hardware acceleration present in the machine that is running the application will be
leveraged. The price paid for this is that WPF applications will run only on a minimum of Windows XP
Service Pack 2 because this is, in turn, the minimum requirement for .NET Framework 3.0. Similarly, if
you produce an application that makes use of advanced 3D rendering techniques, such as pixel shaders
and the like, you will require that your end users have sufficient hardware to run such an application. If
you must target operating systems such as Windows 98 or 2000, you may wish to use Windows Forms
instead.
Media
WPF has native support not only for displaying images but also for the playback of audio and video
multimedia.
As well as supporting established images formats—such as bitmap (BMP), Joint Photographics
Expert Group (JPEG), Graphics Interchange Format (GIF), and Portable Network Graphics (PNG) —
there is also an extensibility model for adding support for new image formats as they occur. This is built
on a new API that eliminates some of the limitations of GDI and GDI+, like high fidelity image support.
The System.Windows.Media.Imaging namespace contains much of the functionality for working with
images in WPF, while the System.Windows.Controls.Image class is the WPF control used for displaying an
image. The Image class’s Source property is used to set the location of the image file to display, as shown
in the example in Listing 1–1.
Listing 1–1. Displaying an Image Using the WPF Image Control
<Image Source=" C:\Users\Public\Pictures\Sample Pictures\Desert.jpg"/>
WPF supports the Windows Media Video (WMV), Moving Picture Experts Group (MPEG), and Audio
Video Interleave (AVI) file formats.
However, as the media component for WPF has Windows Media Player running behind the scenes,
WPF can use any other codecs that the Media Player has installed. For the playback of audio and video
files, the System.Windows.Controls.MediaElement control is used, again specifying a Source location of
the file to use, as in Listing 1–2.
Listing 1–2. Playback of a Multimedia File Using the MediaElement Control
<MediaElement Source="C:\Users\Public\Videos\Sample Videos\Wildlife.wmv" />