Home      Discussion      Topics      Dictionary      Almanac
Signup       Login
Windows Presentation Foundation

Windows Presentation Foundation

Overview

The Windows Presentation Foundation (or WPF) is a graphical subsystem for rendering user interfaces in Windows-based applications. WPF was initially released as part of .NET Framework 3.0. Designed to remove dependencies on the aging GDI
Graphics Device Interface
The Graphics Device Interface is a Microsoft Windows application programming interface and core operating system component responsible for representing graphical objects and transmitting them to output devices such as monitors and printers....

 subsystem, WPF is built on DirectX
DirectX
Microsoft DirectX is a collection of application programming interfaces for handling tasks related to multimedia, especially game programming and video, on Microsoft platforms. Originally, the names of these APIs all began with Direct, such as Direct3D, DirectDraw, DirectMusic, DirectPlay,...

, which provides hardware acceleration and enables modern UI features like transparency, gradients and transforms. WPF provides a consistent programming model for building applications and provides a clear separation between the user interface
User interface
The user interface is the aggregate of means by which people—the users—interact with the system—a particular machine, device, computer program or other complex tool...

 and the business logic
Business logic
Business logic is a non-technical term generally used to describe the functional algorithms that handle information exchange between a database and a user interface...

.

WPF also offers a new markup language, known as XAML
XAML
Extensible Application Markup Language is a declarative XML-based language created by Microsoft which is used to initialize structured values and objects. It is available under Microsoft's Open Specification Promise...

 which is an alternative means for defining UI elements and relationships with other UI elements.
Discussion
Ask a question about 'Windows Presentation Foundation'
Start a new discussion about 'Windows Presentation Foundation'
Answer questions from other users
Full Discussion Forum
 
Encyclopedia

The Windows Presentation Foundation (or WPF) is a graphical subsystem for rendering user interfaces in Windows-based applications. WPF was initially released as part of .NET Framework 3.0. Designed to remove dependencies on the aging GDI
Graphics Device Interface
The Graphics Device Interface is a Microsoft Windows application programming interface and core operating system component responsible for representing graphical objects and transmitting them to output devices such as monitors and printers....

 subsystem, WPF is built on DirectX
DirectX
Microsoft DirectX is a collection of application programming interfaces for handling tasks related to multimedia, especially game programming and video, on Microsoft platforms. Originally, the names of these APIs all began with Direct, such as Direct3D, DirectDraw, DirectMusic, DirectPlay,...

, which provides hardware acceleration and enables modern UI features like transparency, gradients and transforms. WPF provides a consistent programming model for building applications and provides a clear separation between the user interface
User interface
The user interface is the aggregate of means by which people—the users—interact with the system—a particular machine, device, computer program or other complex tool...

 and the business logic
Business logic
Business logic is a non-technical term generally used to describe the functional algorithms that handle information exchange between a database and a user interface...

.

WPF also offers a new markup language, known as XAML
XAML
Extensible Application Markup Language is a declarative XML-based language created by Microsoft which is used to initialize structured values and objects. It is available under Microsoft's Open Specification Promise...

 which is an alternative means for defining UI elements and relationships with other UI elements. A WPF application can be deployed on the desktop or hosted in a web browser. It also enables rich control, design, and development of the visual aspects of Windows programs. It aims to unify a number of application services: user interface, 2D and 3D drawing, fixed and adaptive documents
Document file format
A document file format is a text or binary file format for storing documents on a storage media, especially for use by computers.There currently exist a multitude of incompatible document file formats....

, advanced typography
Typography
Typography is the art and technique of arranging type, type design, and modifying type glyphs. Type glyphs are created and modified using a variety of illustration techniques...

, vector graphics
Vector graphics
Vector graphics is the use of geometrical primitives such as points, lines, curves, and shapes or polygon, which are all based on mathematical equations, to represent images in computer graphics....

, raster graphics
Raster graphics
In computer graphics, a raster graphics image or bitmap is a data structure representing a generally rectangular grid of pixels, or points of color, viewable via a monitor, paper, or other display medium...

, animation
Animation
Animation is the rapid display of a sequence of images of 2-D or 3-D artwork or model positions in order to create an illusion of movement. It is an optical illusion of motion due to the phenomenon of persistence of vision, and can be created and demonstrated in a number of ways...

, data binding
XML data binding
XML data binding refers to the process of representing the information in an XML document as an object in computer memory. This allows applications to access the data in the XML from the object rather than using the DOM or SAX to retrieve the data from a direct representation of the XML itself.An...

, audio and video
Video
Video is the technology of electronically capturing, recording, processing, storing, transmitting, and reconstructing a sequence of still images representing scenes in motion.-History:...

.

WPF is included with Windows 7, Windows Vista
Windows Vista
Windows Vista is a line of operating systems developed by Microsoft for use on personal computers, including home and business desktops, laptops, tablet PCs, and media center PCs...

 and Windows Server 2008, and is also available for Windows XP
Windows XP
Windows XP is a line of operating systems produced by Microsoft for use on personal computers, including home and business desktops, laptops, and media centers. The name "XP" is short for "eXPerience"...

 Service Pack 2 or later, and Windows Server 2003.

Microsoft Silverlight
Microsoft Silverlight
Microsoft Silverlight is a web application framework, integrating multimedia, graphics, animations and interactivity into a single runtime environment. Initially released as a video streaming plugin, later versions brought additional interactivity features and support for .NET languages and...

 is a web-based subset of WPF that enables Flash
Adobe Flash
Adobe Flash is a multimedia platform originally acquired by Macromedia and currently developed and distributed by Adobe Systems. Since its introduction in 1996, Flash has become a popular method for adding animation and interactivity to web pages...

-like web and mobile applications with the same programming model as .NET applications. 3D features are not supported, but XPS
XML Paper Specification
The Open XML Paper Specification , is a specification for a page description language and a fixed-document format originally developed by Microsoft as XML Paper Specification that was later standardized by Ecma International as international standard ECMA-388...

 and vector-based drawing are included.

Graphical services

  • All graphic, including desktop items like windows, are rendered using Direct3D
    Direct3D
    Direct3D is part of Microsoft's DirectX API. Direct3D is only available for Microsoft's various Windows operating systems and in the open source software Wine. It is the base for the graphics API on the Xbox and Xbox 360 console systems. Direct3D is used to render three dimensional graphics in...

    .
    • This aims to provide a unified avenue for displaying graphics and is the enabling factor that allows 2D, 3D, media and animation to be combined in a single window.
    • Allows more advanced graphical features when compared to Windows Forms and its GDI underpinnings.
    • Routing the graphics through Direct3D allows Windows to offload some graphics tasks to the GPU
      Graphics processing unit
      A graphics processing unit or GPU is a specialized processor that offloads 3D graphics rendering from the microprocessor. It is used in embedded systems, mobile phones, personal computers, workstations, and game consoles...

       found on the computer's graphics card. This can reduce the workload on the computer's CPU
      Central processing unit
      The Central Processing Unit or processor is the portion of a computer system that carries out the instructions of a computer program, and is the primary element carrying out the computer's functions. This term has been in use in the computer industry at least since the early 1960s...

      . Since GPUs are fast, parallel pixel processors this also tends to speed up screen refreshes.
    • Supports vector-based graphics, which allow lossless scaling.
    • Supports 3D model rendering and interaction in 2D applications.
    • Interactive 2D content can be overlaid on 3D surfaces, natively.

Data binding

  • WPF has a built-in set of data services to enable application developers to bind and manipulate data within applications. There exists support for three types of data binding:
    • one time: where the client ignores updates on the server.
    • one way: where the client has read-only access to data.
    • two way: where client can read from and write data to the server.
  • LINQ
    Language Integrated Query
    Language Integrated Query is a Microsoft .NET Framework component that adds native data querying capabilities to .NET languages....

     queries, specifically LINQ to XML, can also act as data sources for data binding.
  • Binding of data has no bearing on its presentation. WPF provides data templates to control presentation of data.

  • A set of built-in controls is provided as part of WPF, containing items such as button, menu, grids and list box.
  • A powerful concept in the WPF is the logical separation of a control from its appearance.
    • A control's template can be overridden to completely change its visual appearance.
    • A control can contain any other control or layout, allowing for unprecedented control over composition.
  • Features retained mode graphics, so that applications do not have to be bothered with repainting the display.

Media Services

  • WPF provides an integrated system for building user interfaces with common media elements like vector and raster images, audio and video. WPF also provides an animation system and a 2D/3D rendering system.
  • WPF provides shape primitives for 2D graphics along with a built-in set of brushes, pens, geometries, and transforms.
  • The 3D capabilities in WPF are a subset of the full feature set provided by Direct3D. However, WPF provides tighter integration with other features like user interfaces, documents, and media. This makes it possible to have 3D user interfaces, 3D documents, or 3D media.
  • There is support for most common image formats: BMP, JPEG, PNG, TIFF, Windows Media Photo, GIF, and ICON.
  • WPF supports the video formats WMV, MPEG and some AVI
    Avi
    Avi may refer to:* Avi , the pen name of children's author Edward Irving WortisAVI may refer to:* Audio Video Interleave, a multimedia container format* Judged By Your Work Party* AVI Foodsystems, Inc., a foodservice company...

     files by default, but since it is Windows Media Player running beneath, WPF can use all the codecs installed for it.

Layout

  • WPF provides a sophisticated layout system that handles the arrangement of all visual elements.
  • The Layout engine uses a two phase system.
    • First is the measure phase, where every element in the UI tree is queried for its desired size.
    • Second is the layout phase, where each element is instructed as to its actual size and location.
    • This is a recursive process.
  • WPF ships with a handful of layout panels (StackPanel, WrapPanel, Canvas, UniformGrid, Grid, DockPanel) with each panel specializing in a particular type of layout.
  • WPF also provides a transformation engine.
    • All tranforms in WPF are eventually turned into Direct3D instructions which then become native GPU TRANSFORM instructions.
    • WPF exposes a number of Transform classes (Matrix, Rotation, Scale, Translate, Skew).

Templates

  • In WPF you can define the look of an element directly, via its properties, or indirectly with a Template or Style. At its simplest a style is a combination of property settings that can be applied to a UI element with a single property attribute. Templates are a mechanism for defining alternate UI for portions of your WPF application. There are several template types available in WPF (ControlTemplate, DataTemplate, HierarchicalDataTemplate and ItemsPanelTemplate).

Control Templates
  • Underlying all UI controls in WPF is a new composition model. Every control is composed of one or more ‘visuals’. These visual sub-elements are turned into a hierarchical Visual Tree by WPF and eventually rendered by the GPU. Because WPF controls are not wrappers for standard Windows controls their UI can be radically changed without affecting the normal behavior of the control.
  • Every control in WPF has a default ‘template’ that defines its visual tree. The default template is created by the control author and is replaceable by other developers and designers. The substitute UI is placed within a ControlTemplate.

Data Templates
  • WPF has a flexible data binding system. UI elements can be populated and synchronized with data from an underlying data model. Rather than showing simple text for the bound data WPF can apply a Data Template (replaceable UI for .NET types) before rendering to the Visual Tree.

Animations

  • WPF supports time-based animations, in contrast to the frame-based approach. This decouples the speed of the animation from how the system is performing.
  • WPF supports low level animation via timers and higher level abstractions of animations via the Animation classes.
    • Any WPF element property can be animated as long as it is registered as a Dependency Property.
    • Animation classes are based on the .NET type of property to be animated. For instance, changing the color of a element is done with the ColorAnimation class and animating the Width of an element (which is typed as a Double) is done with the DoubleAnimation class.
  • Animations can be grouped into Storyboards.
  • Animations can be triggered by external events, including user action.
  • Scene redraws are time triggered.
  • Presentation timers are initialized and managed by WPF.
  • Animation effects can be defined on a per-object basis, which can be accessed directly from XAML
    XAML
    Extensible Application Markup Language is a declarative XML-based language created by Microsoft which is used to initialize structured values and objects. It is available under Microsoft's Open Specification Promise...

     markup.

Imaging

  • WPF can natively access Windows Imaging Component
    Windows Imaging Component
    The Windows Imaging Component is a Component Object Model based imaging codec framework introduced in Windows Vista and Windows XP Service Pack 3 for working with and processing digital images and image metadata. It allows applications supporting the framework to automatically get support of...

     (WIC) code and APIs allowing developers to write image codecs for their specific image file formats.

Effects

  • WPF 3.0 provides for BitmapEffects, which are raster effects applied to a Visual. These raster effects are written in unmanaged code and force rendering of the Visual to be performed on the CPU and not hardware accelerated by the GPU. BitmapEffects were deprecated in .NET 3.5 SP 1.
  • .NET Framework 3.5 SP1 adds the Effect class, which is a Pixel-Shader 2.0 effect that can be applied to a visual, which allows all rendering to remain on the GPU.
  • The Effect class is extensible allowing application to specify their own shader effects.
  • .NET 3.5 SP1 ships with two built-in effects, BlurEffect and DropShadowEffect.

Documents

  • WPF natively supports paginated documents. It provides the DocumentViewer class, which is for reading fixed layout documents. The FlowDocumentReader class offers different view modes such as per-page or scrollable and also reflows text if the viewing area is re sized.
  • Natively supports XML Paper Specification
    XML Paper Specification
    The Open XML Paper Specification , is a specification for a page description language and a fixed-document format originally developed by Microsoft as XML Paper Specification that was later standardized by Ecma International as international standard ECMA-388...

     documents.
  • Supports reading and writing paginated documents using Open Packaging Convention
    Open Packaging Convention
    The Open Packaging Conventions is a file packaging format initially created by Microsoft for storing a combination of XML and non-XML files that together form a single entity like an Open XML Paper Specification document in a single compressed file container...

    .

Text

  • WPF includes a number of typographic and text rendering features that were not available in GDI
    Graphics Device Interface
    The Graphics Device Interface is a Microsoft Windows application programming interface and core operating system component responsible for representing graphical objects and transmitting them to output devices such as monitors and printers....

    . This is the first Windows programming interface to expose OpenType
    OpenType
    OpenType is a format for scalable computer fonts. It was built on its predecessor TrueType, retaining TrueType's basic structure and adding many intricate data structures for prescribing typographic behavior....

     features to software developers, supporting OpenType, TrueType, and OpenType CFF (Compact Font Format) fonts.

  • Support for OpenType typographic features includes:
    • Ligatures
      Ligature (typography)
      In writing and typography, a ligature occurs where two or more graphemes are joined as a single glyph. Ligatures usually replace consecutive characters sharing common components and are part of a more general class of glyphs called "contextual forms" where the specific shape of a letter depends on...

    • Old-style numerals
      Text figures
      Text figures are numerals typeset with varying heights in a fashion that resembles a typical line of running text, hence the name...

       (for example, parts of the glyph hang below the text baseline)
    • Swash
      Swash (typography)
      A swash is a typographical flourish on a glyph, like an exaggerated serif.Capital swash characters, which extended to the left, such as those shown in the example on this page, were often used to begin sentences. There were also minuscule swash characters, which came either extending to the left,...

       variants
    • Fractions
    • Superscript and Subscript
    • Small caps
      Small caps
      In typography, small capitals are uppercase characters set at the same height as surrounding lowercase letters or text figures...

    • Line-level justification
      Justification (typesetting)
      In typesetting, justification is the typographic alignment setting of text or images within a column or "measure" to align along both the left and right margin...

    • Ruby character
      Ruby character
      are small, annotative glosses that can be placed above or to the right of a Chinese character when writing languages with logographic characters such as Chinese or Japanese to show the pronunciation...

      s
    • Glyph substitution
      Font substitution
      Font substitution is the process of using one font in place of another when the intended font either is not available or does not contain glyphs for the required characters....

    • Multiple baselines
      Baseline (typography)
      In typography and penmanship, the baseline is the line upon which most letters "sit" and below which descenders extend.In the example to the right, the letter 'p' has a descender; the other letters sit on the baseline....

    • Contextual and Stylistic Alternates
    • Kerning
      Kerning
      In typography, kerning—less commonly, mortising — is the process of adjusting letter spacing in a proportional font. In a well-kerned font, the two-dimensional blank spaces between each pair of letters all have similar area.- In metal typesetting :...


  • WPF handles texts in Unicode
    Unicode
    Unicode is a computing industry standard allowing computers to consistently represent and manipulate text expressed in most of the world's writing systems...

    , and handles texts independent of global settings, such as system locale. In addition, fallback mechanisms are provided to allow writing direction (horizontal versus vertical) handled independent of font name; building international fonts from composite fonts, using a group of single-language fonts; composite fonts embedding. Font linking and font fallback information is stored in a portable XML file, using composite font technology. The XML file has extension .CompositeFont.

  • The WPF text engine also supports built-in spell checking. It also supports such features as automatic line spacing, enhanced international text, language-guided line breaking, hyphenation, and justification, bitmap effects, transforms, and text effects such as shadows, blur, glow, rotation etc. Animated text is also supported; this refers to animated glyphs, as well as real-time changes in position, size, color, and opacity of the text.

  • WPF text rendering takes advantage of advances in ClearType
    ClearType
    ClearType is a trademark for Microsoft's implementation of subpixel rendering technology. ClearType attempts to improve the appearance of text on certain types of computer display screens by sacrificing color fidelity for additional intensity variation. This trade-off is asserted to work well on...

     technology, such as sub-pixel positioning, natural advance widths, Y-direction anti-aliasing, hardware-accelerated
    Hardware acceleration
    In computing, hardware acceleration is the use of hardware to perform some function faster than is possible in software running on the general purpose CPU...

     text rendering, as well as aggressive caching of pre-rendered text in video memory. ClearType cannot be turned off in WPF applications. Unlike the ClearType in GDI or GDI+, WPF ClearType does not snap glyphs to pixels horizontally, leading to a loss of contrast disliked by some users.

  • The extent to which glyphs are cached is dependent on the video card. DirectX
    DirectX
    Microsoft DirectX is a collection of application programming interfaces for handling tasks related to multimedia, especially game programming and video, on Microsoft platforms. Originally, the names of these APIs all began with Direct, such as Direct3D, DirectDraw, DirectMusic, DirectPlay,...

     10 cards are able to cache the font glyphs in video memory
    Video memory
    Video memory is a term generally used in computers to describe some form of writable memory, usually RAM, dedicated to the purpose of holding the information necessary for a graphics card to drive a display device...

    , then perform the composition (assembling of character glyphs in the correct order, with the correct spacing), alpha-blending (application of anti-aliasing), and RGB blending (ClearType's sub-pixel color calculations), entirely in hardware. This means that only the original glyphs need to be stored in video memory once per font (Microsoft estimates that this would require 2 MB of video memory per font), and other operations such as the display of anti-aliased text on top of other graphics—including video—can also be done with no computation effort on the part of the CPU. DirectX 9 cards are only able to cache the alpha-blended glyphs in memory, thus requiring the CPU to handle glyph composition and alpha-blending before passing this to the video card. Caching these partially-rendered glyphs requires significantly more memory (Microsoft estimates 5 MB per process). Cards that don't support DirectX 9 have no hardware-accelerated text rendering capabilities.

Annotations

  • Annotations can be applied on a per-object basis, for objects in a Document or FlowDocument.
  • WPF only provides the capability for creating, storing and managing annotations; each application must expose the UI on their own.

Interoperability

  • WPF provides interoperability with the Windows API
    Windows API
    The Windows API, informally WinAPI, is Microsoft's core set of application programming interfaces available in the Microsoft Windows operating systems. It was formerly called the Win32 API; however, the name Windows API more accurately reflects its roots in 16-bit Windows and its support on 64-bit...

    : Via hosting, one can use Windows Presentation Foundation inside existing Win32 code, or one can use existing Win32 code inside Windows Presentation Foundation.
  • Interoperability with Windows Forms
    Windows Forms
    Windows Forms is the name given to the graphical application programming interface included as a part of Microsoft's .NET Framework, providing access to the native Microsoft Windows interface elements by wrapping the existing Windows API in managed code...

     is also possible through the use of the ElementHost and WindowsFormsHost classes.

Alternative input

  • WPF supports digital ink-related functionality.
  • WPF 4.0 will support multi-touch input on Windows 7 computers.

Accessibility

  • WPF supports Microsoft UI Automation
    Microsoft UI Automation
    Microsoft UI Automation is an Application Programming Interface for User Interface accessibility that is designed to help Assistive Technology products interact with standard and custom UI elements of an application as well as to access, identify, and manipulate an application's UI elements...

     to allow developers to create accessible interfaces.
  • This API also allows automated test scripts to interact with the UI.

XAML


Following the success of markup language
Markup language
A markup language is a system for annotating a text in a way which is syntactically distinguishable from that text. Examples include revision instructions by editors, traditionally written with a blue pencil on authors' manuscripts, typesetting instructions such those found in troff and LaTeX, and...

s for web development, WPF introduces a new language known as eXtensible Application Markup Language (XAML) (pronounced as "Zammel"), which is based on XML
XML
XML is a set of rules for encoding documents electronically. It is defined in the produced by the W3C and several other related specifications; all are fee-free open standards....

. XAML is designed as a more efficient method of developing application user interfaces.

The specific advantage that XAML brings to WPF is that XAML is a completely declarative language. In a declarative programming language, the developer (or designer) describes the behavior and integration of components without the use of procedural programming
Procedural programming
Procedural programming can sometimes be used as a synonym for imperative programming , but can also refer to a programming paradigm based upon the concept of the procedure call...

. Although it is rare that an entire application will be built completely in XAML, the introduction of XAML allows application designers to more effectively contribute to the application development cycle. Using XAML to develop user interfaces also allows for separation of model and view, which is considered a good architectural principle. In XAML, elements and attributes map to classes and properties in the underlying APIs.

As in web development, both layouts and specific themes are well suited to markup, but XAML is not required for either. Indeed, all elements of WPF may be coded in a .NET language (C#, VB.NET). The XAML code can ultimately be compiled into a managed assembly in the same way all .NET languages are.

Architecture



The architecture of WPF spans across both managed code
Managed code
Managed code is computer program code that executes under the management of a virtual machine, unlike unmanaged code, which is executed directly by the computer's CPU. The benefits of managed code include programmer convenience and enhanced security guarantees.Programs in any programming language...

 and native code components. However, the public API exposed is only available via managed code. While the majority of WPF is in managed code, the composition engine which renders the WPF applications is a native component. It is named Media Integration Layer (MIL) and resides in milcore.dll. It interfaces directly with DirectX
DirectX
Microsoft DirectX is a collection of application programming interfaces for handling tasks related to multimedia, especially game programming and video, on Microsoft platforms. Originally, the names of these APIs all began with Direct, such as Direct3D, DirectDraw, DirectMusic, DirectPlay,...

 and provides basic support for 2D and 3D surfaces, timer-controlled manipulation of contents of a surface with a view to exposing animation constructs at a higher level, and compositing
Function composition
In mathematics, function composition is the application of one function to the results of another. For instance, the functions and can be composed by computing the output of g when it has an argument of f instead of x...

 the individual elements of a WPF application into a final 3D "scene" that represents the UI of the application and renders it to the screen. The media codecs are also implemented in unmanaged code, and are shipped as windowscodecs.dll. In the managed world, PresentationCore (presentationcore.dll) provides a managed wrapper for MIL and implements the core services for WPF, including a property system that is aware of the dependencies between the setters and consumers of the property, a message dispatching system by means of a Dispatcher object to implement a specialized event system and services which can implement a layout system such as measurement for UI elements. PresentationFramework (presentationframework.dll) implements the end-user presentational features, including layouts, time-dependent, story-board based animations, and data binding.

WPF exposes a property system for objects which inherit from DependencyObject, that is aware of the dependencies between the consumers of the property, and can trigger actions based on changes in properties. Properties can be either hard coded values or expressions, which are specific expressions that evaluate to a result. In the initial release, however, the set of expressions supported is closed. The value of the properties can be inherited from parent objects as well. WPF properties support change notifications, which invoke bound behaviors whenever some property of some element is changed. Custom behaviors can be used to propagate a property change notification across a set of WPF objects. This is used by the layout system to trigger a recalculation of the layout on property-changes, thus exposing a declarative programming
Declarative programming
In computer science, declarative programming is a programming paradigm that expresses the logic of a computation without describing its control flow. Many languages applying this style attempt to minimize or eliminate side effects by describing what the program should accomplish, rather than...

 style for WPF, whereby almost everything, from setting colors and positions to animating elements can be achieved by setting properties. This allows WPF applications to be written in XAML
XAML
Extensible Application Markup Language is a declarative XML-based language created by Microsoft which is used to initialize structured values and objects. It is available under Microsoft's Open Specification Promise...

, which is a declarative mark-up language, by binding the keywords and attributes directly to WPF classes and properties.

The UI elements of a WPF application are maintained as a class of Visual objects. Visual objects provide a managed interface to a composition tree which is maintained by Media Integration Layer (MIL). Each element of WPF creates and adds one or more composition nodes to the tree. The composition nodes contain rendering instructions, such as clipping and transformation instructions, along with other visual attributes. Thus the entire application is represented as a collection of composition nodes, which are stored in a buffer in the system memory. Periodically, MIL walks the tree and executes the rendering instructions in each node, thus compositing each element on to a DirectX surface, which is then rendered on screen. MIL uses the painter's algorithm
Painter's algorithm
The painter's algorithm, also known as a priority fill, is one of the simplest solutions to the visibility problem in 3D computer graphics...

, where all the components are rendered from back of the screen to the front, which allows complex effects like transparencies to be easily achieved. This rendering process is hardware accelerated using the GPU. The composition tree is cached by MIL, creating a retained mode graphics
Retained mode
In computing, retained mode rendering is a style for application programming interfaces of graphics libraries, in which the libraries retain a complete model of the objects to be rendered.-Overview:...

, so that any changes to the composition tree needs only to be incrementally communicated to MIL. This also frees the applications of managing repainting the screen, MIL can do that itself as it has all the information necessary. Animations can be implemented as time-triggered changes to the composition tree. On the user visible side, animations are specified declaratively, by setting some animation effect to some element via a property and specifying the duration. The code-behind updates the specific nodes of the tree, via Visual objects, to represent both the intermediate states at specified time intervals as well as the final state of the element. MIL will render the changes to the element automatically.

All WPF applications start with two threads: one for managing the UI and another background thread for handling rendering and repainting. Rendering and repainting is managed by WPF itself, without any developer intervention. The UI thread houses the Dispatcher (via an instance of DispatcherObject), which maintains a queue of UI operations that need to be performed (as a tree of Visual objects), sorted by priority. UI events, including changing a property that affects the layout, and user interaction events raised are queued up in the dispatcher, which invokes the handlers for the events. Microsoft recommends that the event handlers only update the properties to reflect new content for application responsiveness; the new content be generated or retrieved in a background thread. The render thread picks up a copy of the visual tree and walks the tree calculating which components will be visible and renders them to Direct3D surfaces. The render thread also caches the visual tree, so only changes to the tree need to be communicated, which will result in updating only the changed pixels. WPF supports an extensible layout model. Layout is divided into two phases: Measure and Arrange. The Measure phase recursively calls all elements and determine the size they will take. In the Arrange phase, the child elements are recursively arranged by their parents, invoking the layout algorithm of the layout module in use.

Tools


There are a number of development tools available for developing Windows Presentation Foundation applications.

Microsoft Tools

  • Microsoft Visual Studio 2008 is a developer-oriented tool that contains a combination XAML editor and WPF visual designer. The WPF designer add-in, codenamed Cider, is a WYSIWYG editor for creating WPF windows, pages and user controls.
  • Microsoft Expression Blend is a designer-oriented tool that provides an artboard for the creation of WPF applications with 2D and 3D graphics, text and forms content. It generates XAML that may be exported into other tools and shares solution (sln files) and project formats (csproj, vbproj) with Microsoft Visual Studio.
  • Microsoft Expression Design
    Microsoft Expression Design
    Microsoft Expression Design is Microsoft's commercial professional illustration vector and raster graphic design tool for web images based on Creature House Expression, which was acquired by Microsoft in 2003. It is part of the Microsoft Expression Studio suite...

     is a bitmap and 2D-vector graphics tool that allows export to XAML.
  • XAMLPad
    XAMLPad
    XAMLPad is a lightweight tool provided with the .NET Framework 3.0 SDK to quickly create simple Extensible Application Markup Language files. It provides a split screen where the XAML code can be typed and immediately previewed in the above XAML renderer.....

     is a lightweight tool included in the .NET Framework SDK. It can create and render XAML files using a split screen UI layout. It also provides a tree view of the markup in a panel.

Third Party Tools

  • An improved version of XAMLPad, called XamlPadX v3, can be downloaded from the author's blog.
  • Kaxaml is an open source
    Open source
    Open source is an approach to the design, development, and distribution of software, offering practical accessibility to a software's source code. Some consider open source as one of various possible design approaches, while others consider it a critical strategic element of their operations...

     WPF designer with a XAML auto-complete editor. It provides a split screen for viewing both the XAML and the rendered UI. It also offers a plug-in model and contains a color picker, code snippet, screen capture and XAML scrubber plug-ins.
  • Ultimate XAML for Softimage is a plugin for Autodesk Softimage and ModTool that allows models to be built using real time shaders which mimic WPF's rendering behavior. In addition to the design time WPF shaders, it can export XAML and can also generate C# code that provides type safe use of the assets within .NET programs.
  • ZAM 3D is a 3D modeling tool that generates 3D models and supports exporting these models to XAML files.

Deployment

  • WPF's deployment model offers both standalone and XAML Browser Applications (XBAP) flavors. The programming model for building either flavor of application is similar.
    • Standalone applications are those that have been locally installed on the computer using software such as ClickOnce
      ClickOnce
      ClickOnce is a Microsoft technology for deploying Windows Forms or Windows Presentation Foundation-based software, also called Smart clients. It is similar to Java Web Start for the Java Platform.ClickOnce is only available in .NET 2.0 and later...

       or Windows Installer
      Windows Installer
      The Windows Installer is an engine for the installation, maintenance, and removal of software on modern Microsoft Windows systems...

       (MSI) and which run on the desktop. Standalone applications are considered full trust and have full access to a computer's resources.
    • XAML Browser Applications
      XAML Browser Applications
      XAML Browser Applications are Windows programs that are hosted inside a web browser such as Firefox or Internet Explorer. Hosted applications run in a partial trust sandbox environment, and are not given full access to the computer's resources and not all WPF functionality is available. The hosted...

       (XBAPs) are programs that are hosted inside a web browser
      Web browser
      A web browser is a software application for retrieving, presenting, and traversing information resources on the World Wide Web. An information resource is identified by a Uniform Resource Identifier and may be a web page, image, video, or other piece of content...

      . Hosted applications run in a partial trust sandbox
      Sandbox (computer security)
      In computer security, a sandbox is a security mechanism for separating running programs. It is often used to execute untested code, or untrusted programs from unverified third-parties, suppliers and untrusted users....

       environment, and are not given full access to the computer's resources and not all WPF functionality is available. The hosted environment is intended to protect the computer from malicious applications. Starting an XBAP (pronounced "ex-bap") from an HTML page or vice versa is seamless (there is no security or installation prompt). Although one gets the perception of the application running in the browser, it actually runs in an out-of-process executable different from the browser.

Firefox blocking WPF installation


With the release of .NET Framework 3.5 SP1 they also run in Mozilla Firefox using the included XBAP extension. However, on October 16th, 2009, Mozilla added the Firefox plugin and Extension to its add-ons blocklist, because of a remotely exploitable serious security vulnerability.

Microsoft Silverlight



Silverlight (codenamed WPF/E) is a cross-browser browser plugin which contains WPF-based technology (including XAML) that provides features such as video, vector graphics, and animations to multiple operating systems including Windows Vista
Windows Vista
Windows Vista is a line of operating systems developed by Microsoft for use on personal computers, including home and business desktops, laptops, tablet PCs, and media center PCs...

, Windows XP
Windows XP
Windows XP is a line of operating systems produced by Microsoft for use on personal computers, including home and business desktops, laptops, and media centers. The name "XP" is short for "eXPerience"...

, and Mac OS X
Mac OS X
Mac OS X is a line of computer operating systems developed, marketed, and sold by Apple Inc., and since 2002 has been included with all new Macintosh computer systems...

, with Microsoft sanctioned 3rd party developers working on ports for Linux
Linux
Linux is a generic term referring to Unix-like computer operating systems based on the Linux kernel. Their development is one of the most prominent examples of free and open source software collaboration; typically all the underlying source code can be used, freely modified, and redistributed,...

 distributions. Specifically, it is currently provided as an add-on for Mozilla Firefox
Mozilla Firefox
Mozilla Firefox is a free and open source web browser descended from the Mozilla Application Suite and managed by Mozilla Corporation. Firefox has 23.75% of the recorded usage share of web browsers , making it the second most popular browser in terms of current use worldwide after Microsoft's...

, Internet Explorer 6
Internet Explorer 6
Internet Explorer 6 is the sixth major revision of Internet Explorer, a web browser developed by Microsoft for Windows operating systems....

 and above, Google Chrome
Google Chrome
Google Chrome is a web browser released by Google which uses the WebKit layout engine and application framework. It was first released as a beta version for Microsoft Windows on September 2 2008, and the public stable release was on December 11 2008. The name is derived from the graphical user...

 and Apple Safari
Safari (web browser)
Safari is a web browser developed by Apple Inc. First released as a public beta on 7 January 2003 on the company's Mac OS X operating system, it became Apple's default browser beginning with Mac OS X v10.3 "Panther". Apple has also made Safari the native browser for the iPhone OS...

. Silverlight and WPF only share the XAML presentation layer.

.NET Micro Framework


The .NET Micro Framework
.NET Micro Framework
The .NET Micro Framework is a .NET platform for extremely resource-constrained devices. It includes a small version of the .NET CLR and supports development in C# and debugging , both using Microsoft Visual Studio...

 includes a GUI object model loosely based on WPF, although without support for XAML.

See also

  • Desktop Window Manager
    Desktop Window Manager
    Desktop Window Manager is the desktop graphical user interface system in Windows Vista and Windows 7 that enables the Windows Aero graphical user interface and visual theme. The Desktop Window Manager requires video cards supporting DirectX 9.0 and Shader Model 2.0...

  • Computer graphics
    Computer graphics
    Computer graphics are graphics created using computers and, more generally, the representation and manipulation of pictorial data by a computer....

  • Windows Graphics Foundation
  • Windows Vista printing technologies
  • Comparison of user interface markup languages
    Comparison of user interface markup languages
    The following tables compare general and technical information for a number of user interface markup languages. Please see the individual markup languages' articles for further information...

  • Microsoft Family.Show
    Microsoft Family.Show
    Microsoft Family.Show is a free genealogy program, created as a reference sample for Microsoft's Windows Presentation Foundation.As a reference sample it has the following limitations:* Supports only a single birth, marriage, and death events per person....

     - created as a reference sample for the Windows Presentation Foundation.
  • Model view viewmodel
    Model View ViewModel
    The Model View ViewModel is an architectural pattern used in software engineering that originated from Microsoft as a specialization of the PresentationModel design pattern introduced by Martin Fowler specific for the Windows Presentation Foundation...

     - an architectural pattern developed for taking advantage of WPF's unique capabilities.

Further reading

  • Adam Nathan
    Adam Nathan
    Adam Nathan is a technical author/speaker, and currently works as a software developer at Microsoft. Adam is the core architect of Microsoft Popfly. He has been involved with .NET technologies from the beginning, and has written a 1,600-page book on .NET/COM Interoperability...

    : Windows Presentation Foundation Unleashed (WPF), December 21, 2006, Sams Publishing, ISBN 0-672-32891-7
  • Chris Anderson
    Chris Anderson
    Chris or Christopher Anderson may refer to:* Chris Anderson , curator of the TED Conference* Chris Anderson , author, journalist, editor-in-chief of Wired Magazine, popularized "The Long Tail"...

    : Essential Windows Presentation Foundation (WPF), April 11, 2007, Addison-Wesley, ISBN 0-321-37447-9

External links