Windows Presentation Foundation
Encyclopedia
Developed by Microsoft
Microsoft
Microsoft Corporation is an American public multinational corporation headquartered in Redmond, Washington, USA that develops, manufactures, licenses, and supports a wide range of products and services predominantly related to computing through its various product divisions...

, the Windows Presentation Foundation (or WPF) is a computer-software
Computer software
Computer software, or just software, is a collection of computer programs and related data that provide the instructions for telling a computer what to do and how to do it....

 graphical subsystem for rendering user interfaces in Windows-based applications. WPF, previously known as "Avalon", was initially released as part of .NET Framework 3.0. Rather than relying on the older 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 utilizes 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,...

. WPF attempts to provide a consistent programming model for building applications and provides a separation between the user interface and the business logic
Business logic
Business logic, or domain logic, is a non-technical term generally used to describe the functional algorithms that handle information exchange between a database and a user interface.- Scope of business logic :Business logic:...

. It resembles similar XML
XML
Extensible Markup Language is a set of rules for encoding documents in machine-readable form. It is defined in the XML 1.0 Specification produced by the W3C, and several other related specifications, all gratis open standards....

-oriented object model
Object model
In computing, object model has two related but distinct meanings:# The properties of objects in general in a specific computer programming language, technology, notation or methodology that uses them. For example, the Java objects model, the COM object model, or the object model of OMT...

s, such as those implemented in XUL
XUL
In computer programming, XUL , the XML User Interface Language, is an XML user interface markup language developed by the Mozilla project. XUL operates in Mozilla cross-platform applications such as Firefox...

 and SVG.

WPF employs XAML, a derivative of XML
XML
Extensible Markup Language is a set of rules for encoding documents in machine-readable form. It is defined in the XML 1.0 Specification produced by the W3C, and several other related specifications, all gratis open standards....

, to define and link various UI
User interface
The user interface, in the industrial design field of human–machine interaction, is the space where interaction between humans and machines occurs. The goal of interaction between a human and a machine at the user interface is effective operation and control of the machine, and feedback from the...

 elements. WPF applications can also be deployed as standalone desktop programs, or hosted as an embedded object in a website. WPF aims to unify a number of common user interface
User interface
The user interface, in the industrial design field of human–machine interaction, is the space where interaction between humans and machines occurs. The goal of interaction between a human and a machine at the user interface is effective operation and control of the machine, and feedback from the...

 elements, such as 2D/3D rendering, 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....

, typography
Typography
Typography is the art and technique of arranging type in order to make language visible. The arrangement of type involves the selection of typefaces, point size, line length, leading , adjusting the spaces between groups of letters and adjusting the space between pairs of letters...

, 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 expressions, to represent images in computer graphics...

, runtime 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. The effect is an optical illusion of motion due to the phenomenon of persistence of vision, and can be created and demonstrated in several ways...

, and pre-rendered media. These elements can then be linked and manipulated based on various events, user interactions, and data bindings
XML data binding
XML data binding refers to a means of representing 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 XML data...

.

WPF runtime libraries
Runtime library
In computer programming, a runtime library is a special program library used by a compiler, to implement functions built into a programming language, during the execution of a computer program...

 are included with all versions of Microsoft Windows
Microsoft Windows
Microsoft Windows is a series of operating systems produced by Microsoft.Microsoft introduced an operating environment named Windows on November 20, 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces . Microsoft Windows came to dominate the world's personal...

 since Windows Vista
Windows Vista
Windows Vista is an operating system released in several variations developed by Microsoft for use on personal computers, including home and business desktops, laptops, tablet PCs, and media center PCs...

 and Windows Server 2008. Users of Windows XP
Windows XP
Windows XP is an operating system produced by Microsoft for use on personal computers, including home and business desktops, laptops and media centers. First released to computer manufacturers on August 24, 2001, it is the second most popular version of Windows, based on installed user base...

 SP2/SP3 and Windows Server 2003
Windows Server 2003
Windows Server 2003 is a server operating system produced by Microsoft, introduced on 24 April 2003. An updated version, Windows Server 2003 R2, was released to manufacturing on 6 December 2005...

 can optionally install the necessary libraries.

Microsoft has released four major WPF versions: WPF 3.0 (Nov 2006), WPF 3.5 (Nov 2007), WPF 3.5sp1 (Aug 2008), and WPF 4 (April 2010).

Microsoft Silverlight
Microsoft Silverlight
Microsoft Silverlight is an application framework for writing and running rich Internet applications, with features and purposes similar to those of Adobe Flash. The run-time environment for Silverlight is available as a plug-in for web browsers running under Microsoft Windows and Mac OS X...

 utilizes WPF to provide embedded web controls comparable to Adobe Flash
Adobe Flash
Adobe Flash is a multimedia platform used to add animation, video, and interactivity to web pages. Flash is frequently used for advertisements, games and flash animations for broadcast...

, but with more focus on a UI object model
Object model
In computing, object model has two related but distinct meanings:# The properties of objects in general in a specific computer programming language, technology, notation or methodology that uses them. For example, the Java objects model, the COM object model, or the object model of OMT...

 and less on animation. 3D runtime rendering is unsupported in Silverlight, but available to embedded WPF applications. However, 3D API will be introduced in Silverlight 5 which is planned to be released in 2011.

Direct3D

Graphics, including desktop items like windows, are rendered using Direct3D
Direct3D
Direct3D is part of Microsoft's DirectX application programming interface . Direct3D is available for Microsoft Windows operating systems , and for other platforms through the open source software Wine. It is the base for the graphics API on the Xbox and Xbox 360 console systems...

. This allows the display of more complex graphics and custom themes, at the cost of GDI's
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....

 wider range of support and uniform control theming. It allows Windows to offload some graphics tasks to the GPU
Graphics processing unit
A graphics processing unit or GPU is a specialized circuit designed to rapidly manipulate and alter memory in such a way so as to accelerate the building of images in a frame buffer intended for output to a display...

. This reduces the workload on the computer's CPU
Central processing unit
The central processing unit is the portion of a computer system that carries out the instructions of a computer program, to perform the basic arithmetical, logical, and input/output operations of the system. The CPU plays a role somewhat analogous to the brain in the computer. The term has been in...

. GPUs are optimized for parallel pixel computations, this tends to speed up screen refreshes at the cost of decreased compatibility in markets where GPUs are not necessarily as powerful, such as the netbook
Netbook
Netbooks are a category of small, lightweight, legacy-free, and inexpensive laptop computers.At their inception in late 2007 as smaller notebooks optimized for low weight and low cost — netbooks omitted certain features , featured smaller screens and keyboards, and offered reduced computing...

 market. WPF's emphasis on vector graphics allows most controls and elements to be scaled without loss in quality or pixelization
Pixelization
Pixelization is a video- and image-editing technique in which an image is blurred by displaying part or all of it at a markedly lower resolution. It is primarily used for censorship...

, thus increasing accessibility. With the exception of Silverlight, Direct3D integration allows for streamlined 3D rendering. In addition, 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. It supports three types of data binding:
    1. one time: where the client ignores updates on the server.
    2. one way: where the client has read-only access to data.
    3. 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, although ports exist for Java, PHP and JavaScript....

     queries, including 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 a high degree of control over composition.
  • Features retained mode
    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:...

     graphics. Repainting the display isn't always necessary.

Media Services

  • The 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
    Audio Video Interleave
    Audio Video Interleave , known by its acronym AVI, is a multimedia container format introduced by Microsoft in November 1992 as part of its Video for Windows technology. AVI files can contain both audio and video data in a file container that allows synchronous audio-with-video playback...

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

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 an 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.
    • Storyboards are the primary way to start, stop, pause and otherwise manipulate the animations.
  • 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 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...

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

Effects

  • WPF 3.0 provides for Bitmap effects (BitmapEffect class), 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 applications to specify their own shader effects.
  • The Effect class, in .NET 3.5 SP1 and 4.0, ships with two built-in effects, BlurEffect and DropShadowEffect. There are no direct replacements for OuterGlowBitmapEffect, EmbossBitmapEffect and BevelBitmapEffect, previously provided by the deprecated BitmapEffect class. However there are other ways of achieving the same results with the Effect class. For example, developers can get an outer glow effect by using the DropShadowEffect with its ShadowDepth set to 0.
  • Although the BitmapEffect class was marked as deprecated in .Net Framework 3.5 SP1, its use was still allowed and these effects would still render correctly. In .Net Framework 4.0 the BitmapEffect class was effectively deprecated - code referencing BitmapEffect still builds without errors, but no effect gets actually rendered.

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
    Reflowable document
    A reflowable document is a type of electronic document that can adapt its presentation to the output device. Typical desktop publishing output formats like PostScript or PDF are page-oriented, so are not generally reflowable , whereas the world wide web standard, HTML is a reflowable format.The...

     if the viewing area is resized.
  • Natively supports XML Paper Specification
    XML Paper Specification
    Open XML Paper Specification , is an open 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 container-file technology initially created by Microsoft to store a combination of XML and non-XML files that together form a single entity such as an Open XML Paper Specification document...

    .

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, were historically often used to begin sentences. There were also minuscule swash characters, which came either extending to the left, to begin words, or to the right to...

       variants
    • Fractions
    • Superscript and Subscript
    • Small caps
      Small caps
      In typography, small capitals are uppercase characters set at the same height and weight 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.Font substitution can be aided by:...

    • Multiple baselines
      Baseline (typography)
      In European and West Asian 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 is the process of adjusting the spacing between characters in a proportional font, usually to achieve a visually pleasing result. Kerning is the adjustment of the space between individual letter forms vs. tracking which is the uniform adjustment of spacing applied over a...

  • WPF handles texts in Unicode
    Unicode
    Unicode is a computing industry standard for the consistent encoding, representation and handling of 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 computer 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 older WPF 3.x 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 text rendering engine has been rewritten in WPF 4.0, correcting this issue.
  • 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.

Interoperability

  • Windows Forms
    Windows Forms
    Windows Forms is the name given to the graphical application programming interface included as a part of Microsoft .NET Framework, providing access to native Microsoft Windows interface elements by wrapping the extant 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 supports 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 modern system for annotating a text in a way that is syntactically distinguishable from that text. The idea and terminology evolved from the "marking up" of manuscripts, i.e. the revision instructions by editors, traditionally written with a blue pencil on authors' manuscripts...

s for web development, WPF introduces a new language known as eXtensible Application Markup Language (XAML; icon), which is based on XML
XML
Extensible Markup Language is a set of rules for encoding documents in machine-readable form. It is defined in the XML 1.0 Specification produced by the W3C, and several other related specifications, all gratis 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, allowing the developer (or designer) to describe 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, derived from structured programming, 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 a term coined by Microsoft to identify computer program code that requires and will only execute under the "management" of a Common Language Runtime virtual machine ....

 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, 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 determines 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
    Microsoft Visual Studio
    Microsoft Visual Studio is an integrated development environment from Microsoft. It is used to develop console and graphical user interface applications along with Windows Forms applications, web sites, web applications, and web services in both native code together with managed code for all...

     is a developer-oriented IDE
    Integrated development environment
    An integrated development environment is a software application that provides comprehensive facilities to computer programmers for software development...

     that contains a combination XAML editor and WPF visual designer, beginning with Visual Studio 2008. The WPF designer add-in, codenamed Cider, is a WYSIWYG editor for creating WPF windows, pages and user controls. It was available earlier as a Visual Studio 2005 extensions for .NET Framework 3.0 CTP for the initial release of WPF but is no longer available.
  • Microsoft Visual Studio Express
    Microsoft Visual Studio Express
    Microsoft Visual Studio Express is a set of freeware integrated development environments developed by Microsoft that are lightweight versions of the Microsoft Visual Studio product line. Express Editions were conceived beginning with Visual Studio 2005...

     2008 and later editions, particularly Visual C# Express and Visual Basic Express, also have the WPF designer integrated.
  • 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 for exporting to XAML.
  • XAMLPad
    XAMLPad
    XAMLPad is a lightweight tool originally provided with the .NET Framework 3.0 SDK to quickly create simple Extensible Application Markup Language files...

     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

  • WPF Graphics Tools contains libraries that can read 3ds, svg, emf and wmf files in WPF applications or convert the files into XAML for WPF or Silverlight
    Microsoft Silverlight
    Microsoft Silverlight is an application framework for writing and running rich Internet applications, with features and purposes similar to those of Adobe Flash. The run-time environment for Silverlight is available as a plug-in for web browsers running under Microsoft Windows and Mac OS X...

    . There is also the ultimate Zoom Panel control and Ab3d.PowerToys library that makes work with WPF 3D very easy. All the libraries include samples that demonstrate the power of WPF.
  • An improved version of XAMLPad, called XamlPadX v4, can be downloaded from the author's blog.
  • The open source .NET IDE SharpDevelop includes powerful WPF application design abilities. It is a free alternative to the commercial Microsoft Visual Studio
    Microsoft Visual Studio
    Microsoft Visual Studio is an integrated development environment from Microsoft. It is used to develop console and graphical user interface applications along with Windows Forms applications, web sites, web applications, and web services in both native code together with managed code for all...

     IDE
    Integrated development environment
    An integrated development environment is a software application that provides comprehensive facilities to computer programmers for software development...

    .
  • Danet Studio is compilations of WPF software, provides Word Processing to creating a Flow Document XAML and a reader to read the Flow Document XAML.
  • Kaxaml is an open source
    Open source
    The term open source describes practices in production and development that promote access to the end product's source materials. Some consider open source a philosophy, others consider it a pragmatic methodology...

     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.
  • 3DPaintBrush is a companion tool for XAML. Used to export 3D scenes and models to XAML files.
  • Sybase PowerBuilder .NET is a 4GL tool that translates PowerBuilder code, graphical objects to XAML and allows deploying the application as a WPF target.
  • Snoop is a user-interface spying tool that can inspect the visual tree of WPF applications, allowing to view and change properties of objects at run-time.
  • WPF Inspector is a utility that attaches to a running WPF application to troubleshoot common problems with layouting, databinding or styling. WPF Inspector allows you to explore a live view of the logical- and visual tree, read and edit property values of elements, watch the data context, debug triggers, trace styles and much more.

Deployment

  • WPF's deployment model offers both standalone and XAML Browser Applications (XBAP) flavors. The programming model for building either type 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 that enables the user to install and run a Windows application by clicking a link in a web page. ClickOnce is a component of Microsoft .NET Framework 2.0 and later, supports deploying applications made with Windows Forms or Windows Presentation Foundation...

       or Windows Installer
      Windows Installer
      The Windows Installer is a software component used 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 Presentation Foundation applications that are hosted and run inside a web browser such as Firefox or Internet Explorer...

       (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...

      . Pre-.NET4 XBAP 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, untrusted users and untrusted websites....

       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. XBAPs can run as fully trusted applications in .NET 4, with full access to computer resources. Starting an XBAP 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.

Internet Explorer

As of the release of .NET Framework 3.0, XBAPs would only run in Internet Explorer.

Firefox support

With the release of .NET Framework 3.5 SP1, XBAP also runs in Mozilla Firefox using the included extension. On October 16, 2009, Mozilla added the Firefox plugin and extension to its add-ons blocklist, because of a remotely exploitable serious security vulnerability, in agreement with Microsoft. Two days later, the block was removed. On Windows 7, the Firefox plugin does not run by default. A reinstallation of the .NET Framework 3.5 SP1 will install the plugin and add support for XBAP applications on Firefox. Alternatively hard copying of the plugin DLL
DLL
DLL may refer to:* Data link layer, a layer in the OSI network architecture model* Delay-locked loop, a device to reduce clock skew in digital circuits* Doubly linked list, a data structure in computer programming...

s from a working Windows XP/Vista installation to the plugin directory of Mozilla Firefox will also reinstate support for XBAP applications. The WPF plugin DLLs can be found in the following directories depending on the Framework version:
  • c:\Windows\Microsoft.NET\Framework\v3.5\WPF\NPWPF.dll - for v3.5 [SP1]
  • c:\Windows\Microsoft.NET\Framework\WPF\NPWPF.dll - for v4

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 7, Windows Vista
Windows Vista
Windows Vista is an operating system released in several variations 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 an operating system produced by Microsoft for use on personal computers, including home and business desktops, laptops and media centers. First released to computer manufacturers on August 24, 2001, it is the second most popular version of Windows, based on installed user base...

, and Mac OS X
Mac OS X
Mac OS X is a series of Unix-based operating systems and graphical user interfaces developed, marketed, and sold by Apple Inc. Since 2002, has been included with all new Macintosh computer systems...

. Microsoft sanctioned a limited number of 3rd party developers to work on ports for certain Linux
Linux
Linux is a Unix-like computer operating system assembled under the model of free and open source software development and distribution. The defining component of any Linux system is the Linux kernel, an operating system kernel first released October 5, 1991 by Linus Torvalds...

 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 is the second most widely used browser, with approximately 25% of worldwide usage share of web browsers...

, 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 developed by Google that uses the WebKit layout engine. 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 interface frame, or...

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

. Silverlight and WPF only share the XAML presentation layer.

.NET Micro Framework

The .NET Micro Framework
.NET Micro Framework
The .NET Micro Framework is an Open Source .NET platform for resource-constrained devices with at least 256 KBytes of flash and 64 KBytes of RAM. It includes a small version of the .NET CLR and supports development in C#, Visual Basic .NET, and debugging using Microsoft Visual Studio...

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

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 Anderson may refer to:* Chris Anderson , founder of Future Publishing and curator of the TED Conference* Chris Anderson , author, journalist, editor-in-chief of Wired Magazine, popularized "The Long Tail"* Chris Anderson , football player, educator, former Vice-Chairman of Aberdeen F.C.*...

    : Essential Windows Presentation Foundation (WPF), April 11, 2007, Addison-Wesley, ISBN 0-321-37447-9
  • Chris Sells
    Chris Sells
    Chris Sells is a Microsoft employee and author.- Books :*The Downloader's Companion to Windows 95 ISBN 0-1352-0024-5*Windows Telephony Programming ISBN 0-2016-3450-3*Effective COM ISBN 0-2013-7968-6...

    , Ian Griffiths
    Ian Griffiths
    Ian James Griffiths is an English former footballer.-Playing career:Griffiths played for Tranmere Rovers and Rochdale before joining Port Vale on trial in October 1984. He scored on his full debut, in a 4–1 home win over Scunthorpe United in a second round FA Cup game on 7 December 1984...

    : Programming WPF, August 28, 2007, O'Reilly Media, ISBN 0-596-51037-3
  • Arlen Feldman, Maxx Daymon: WPF in Action with Visual Studio 2008, November 21, 2008, Manning Publications, ISBN 1-933988-22-3

External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK