Windows Presentation Foundation

From Wikipedia, the free encyclopedia - View original article

Jump to: navigation, search
dot net three point zero windows stack diagram
This subsystem is a part of .NET Framework 3.0

Windows Presentation Foundation (or WPF) is a graphical subsystem for rendering user interfaces in Windows-based applications by Microsoft. WPF, previously known as "Avalon", was initially released as part of .NET Framework 3.0. Rather than relying on the older GDI subsystem, WPF uses DirectX. WPF attempts to provide a consistent programming model for building applications and separates the user interface from business logic. It resembles similar XML-oriented object models, such as those implemented in XUL and SVG.

WPF employs XAML, an XML-based language, to define and link various interface elements.[1] 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 elements, such as 2D/3D rendering, fixed and adaptive documents, typography, vector graphics, runtime animation, and pre-rendered media. These elements can then be linked and manipulated based on various events, user interactions, and data bindings.

WPF runtime libraries are included with all versions of Microsoft Windows since Windows Vista and Windows Server 2008. Users of Windows XP SP2/SP3 and Windows Server 2003 can optionally install the necessary libraries.[2][3]

Microsoft Silverlight provides functionality that is mostly a subset of WPF to provide embedded web controls comparable to Adobe Flash. 3D runtime rendering has been supported in Silverlight since Silverlight 5.[4]

History and future[edit]

WPF, previously known as "Avalon", was initially released as part of .NET Framework 3.0. Since then, Microsoft has released five major WPF versions: WPF 3.0 (Nov 2006), WPF 3.5 (Nov 2007), WPF 3.5sp1 (Aug 2008), WPF 4 (April 2010), and WPF 4.5 (August 2012).

According to Microsoft developers answering questions during Build 2014, WPF is still actively developed, but was not designed to be highly responsive, nor adapted to low-power consumer devices such as tablets or smartphones. Because of that, no further major changes are expected to be done on the framework[5]



Graphics, including desktop items like windows, are rendered using Direct3D. This allows the display of more complex graphics and custom themes, at the cost of GDI's wider range of support and uniform control theming. It allows Windows to offload some graphics tasks to the GPU. This reduces the workload on the computer's CPU. 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 market.

The Windows Presentation Foundation (WPF) is Microsoft's UI framework to create applications with a rich user experience. It is part of the .NET framework 3.0 and higher. WPF's emphasis on vector graphics allows most controls and elements to be scaled without loss in quality or pixelization, 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.[6][7]

Data binding[edit]

Media services[edit]


Control Templates

Data Templates







Alternative input[edit]



Following the success of markup languages for web development, WPF introduces eXtensible Application Markup Language (XAML; /ˈzæməl/), which is based on XML. XAML is designed as a more efficient method of developing application user interfaces[citation needed].

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


The WPF architecture. Blue elements are Windows components; brown ones are wpf components.

The architecture of WPF spans across both managed code 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 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 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.[17][18] The media codecs are also implemented in unmanaged code, and are shipped as windowscodecs.dll.[17] In the managed world, PresentationCore (presentationcore.dll) provides a managed wrapper for MIL and implements the core services for WPF,[17] 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.[18] PresentationFramework (presentationframework.dll) implements the end-user presentational features, including layouts, time-dependent, story-board based animations, and data binding.[18]

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.[18] 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 style for WPF, whereby almost everything, from setting colors and positions to animating elements can be achieved by setting properties.[18] 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 interface 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, 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.[18] The composition tree is cached by MIL, creating a retained mode graphics, 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.[19] 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.[19] 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.[18][20]


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

Microsoft tools[edit]

Third party tools[edit]


WPF's deployment model offers both standalone and XAML Browser Applications (XBAP, pronounced "ex-bap") 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 or Windows Installer (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 (XBAPs) are programs that are hosted inside a web browser. Pre-.NET4 XBAP 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 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[edit]

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

Firefox support[edit]

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.[23] Two days later, the block was removed. On Windows 7, the Firefox plugin does not run by default.[24] A reinstallation of the .NET Framework 3.5 SP1 will install the plugin and add support for XBAP applications on Firefox.[25] Alternatively, hard-copying the plugin DLLs from a working Windows XP/Vista installation to the plugin directory of Mozilla Firefox will also reinstate support for XBAP applications.[25] The WPF plugin DLLs reside in the following directories (depending on the Framework version):

3.5 [SP1]

Microsoft Silverlight[edit]

Main article: Microsoft Silverlight

Silverlight (codenamed WPF/E) is a cross-browser browser plugin which contains WPF-based technology (including XAML)[26] that provides features such as video, vector graphics, and animations to multiple operating systems including Windows 7, Windows Vista, Windows XP, and Mac OS X. Microsoft sanctioned a limited number of 3rd party developers to work on ports for certain Linux distributions.[27] Specifically, it is currently provided as an add-on for Mozilla Firefox, Internet Explorer 6 and above, Google Chrome and Apple Safari.

.NET Micro Framework[edit]

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


  1. ^ MSDN.NET Development: WPF: XAML Overview
  2. ^ Microsoft .NET Framework 3.0 Release Notes
  3. ^ Microsoft .NET Framework 3.0 Download
  4. ^ Silverlight Learning Resources. Retrieved on 2013-08-29.
  5. ^ "A WPF Q&A". 2014-04-03. Retrieved 2014-04-21. "WPF is roughly ten to twelve years depending on how you count. And WPF was not designed to be highly responsive. Nor was it designed for the low-power consumer devices such as tablets. It simply wasn’t meant for the kinds of applications people want today. So given these factors, Microsoft is not planning on any investing in major changes to WPF." 
  6. ^ Introducing Windows Presentation Foundation
  7. ^ a b "What's New in WPF 3.5? Here's Fifteen Cool Features...". Retrieved 2007-10-14. 
  8. ^ Graphics and Multimedia. Retrieved on 2013-08-29.
  9. ^ a b c d "Animation overview". MSDN. Retrieved 2007-10-14. 
  10. ^ Typography in Windows Presentation Foundation
  11. ^ MSDN Library: .NET Development: WPF: ClearType Overview
  12. ^ WPF ClearType anti-aliasing cannot be turned off
  13. ^ My first thoughts on WPF with VS 2008 RTM and a few questions : Windows Presentation Foundation (WPF) : .NET Development : MSDN Forums
  14. ^ WPF 4 (VS 2010 and .NET 4.0 Series) - ScottGu's Blog. Retrieved on 2013-08-29.
  15. ^ WPF touch services are badly broken
  16. ^ MSDN Article on UI Automation
  17. ^ a b c Chris Anderson. "MIL information". Retrieved 2007-10-14. 
  18. ^ a b c d e f g "WPF Architecture". MSDN. Retrieved 2007-10-14. 
  19. ^ a b "Threading Model". MSDN. Retrieved 2007-10-14. 
  20. ^ "The Layout System". MSDN. Retrieved 2007-10-14. 
  21. ^
  22. ^ Rich Application Development Tool/Declarative Programming Environment | PowerBuilder - Sybase Inc. Retrieved on 2013-08-29.
  23. ^ "NET Framework Assistant Blocked to Disarm Security Vulnerability". Retrieved 2009-10-17. 
  24. ^ "Firefox Add-ons to Support .NET Application Deployment". Retrieved 2010-09-07. 
  25. ^ a b "Xbap plugin for firefox in Windows 7". Retrieved 2010-09-29. 
  26. ^ ASP.NET: WPF/E - December 2006 Community Technology Preview
  27. ^ "Silverlight 1.0 Released and Silverlight for Linux Announced". Retrieved 2007-09-05. 

Further reading[edit]

External links[edit]