Windows Presentation Foundation

Last updated
Windows Presentation Foundation (WPF)
Original author(s) Microsoft
Developer(s) .NET Foundation
Initial releaseNovember 21, 2006;17 years ago (2006-11-21)
Stable release
v8.0.0 / November 14, 2023;3 months ago (2023-11-14) [1]
Repository
Written in C#, C++, C
Operating system Microsoft Windows
Platform .NET Framework, .NET
Type Software framework
License MIT License
Website learn.microsoft.com/en-us/dotnet/desktop/wpf/

Windows Presentation Foundation (WPF) is a free and open-source graphical subsystem (similar to WinForms) originally developed by Microsoft for rendering user interfaces in Windows-based applications. WPF, previously known as "Avalon", was initially released as part of .NET Framework 3.0 in 2006. WPF uses DirectX and attempts to provide a consistent programming model for building applications. It separates the user interface from business logic, and resembles similar XML-oriented object models, such as those implemented in XUL and SVG. [2]

Contents

Overview

This subsystem is a part of .NET Framework 3.0. DotNet3.0.svg
This subsystem is a part of .NET Framework 3.0.

WPF employs XAML, an XML-based language, to define and link various interface elements. [3] WPF applications can 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. [4]

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. [5] [6]

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

At the Microsoft Connect event on December 4, 2018, Microsoft announced releasing WPF as open source project on GitHub. It is released under the MIT License. Windows Presentation Foundation has become available for projects targeting the .NET software framework, however, the system is not cross-platform and is still available only on Windows. [8] [9]

Features

Direct3D

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.

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. [10] [11]

Data binding

Media services

Templates

Control templates

Data templates

Animations

Imaging

Effects

Documents

Text

Interoperability

To enable the use of WinForms, the developer executes this from their WPF C# code:

 System.Windows.Forms.Integration.WindowsFormsHost.EnableWindowsFormsInterop();

Alternative input

Accessibility

XAML

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. [20] 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.

Architecture

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

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

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. [22] 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. [22] 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. [24]

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. [22] 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. [25] All WPF applications start with two threads: one for managing the UI and another background thread for handling rendering and repainting. [26] 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, with the new content being generated or retrieved in a background thread. [26] 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 just 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. [22] [27]

Tools

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

Microsoft tools

Third-party tools

Deployment

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

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

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. [33] Two days later, the block was removed. On Windows 7, the Firefox plugin does not run by default. [34] A reinstallation of the .NET Framework 3.5 SP1 will install the plugin and add support for XBAP applications on Firefox. [35] 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. [35] The WPF plugin DLLs reside in the following directories (depending on the Framework version):

3.5 [SP1]
C:\Windows\Microsoft.NET\Framework\v3.5\WPF\NPWPF.dll
4.0
C:\Windows\Microsoft.NET\Framework\WPF\NPWPF.dll

Microsoft Silverlight

Silverlight (codenamed WPF/E) is a deprecated cross-browser browser plugin which contained WPF-based technology (including XAML) [36] that provided 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 third-party developers to work on ports for certain Linux distributions. [37] Specifically, it was provided as an add-on for Mozilla Firefox, Internet Explorer 6 and above, Google Chrome 42 and below and Apple Safari.

.NET Micro Framework

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

Related Research Articles

ClearType is Microsoft's implementation of subpixel rendering technology in rendering text in a font system. 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 LCD flat panel monitors.

<span class="mw-page-title-main">Graphics Device Interface</span> Microsoft Windows API

The Graphics Device Interface (GDI) is a legacy component of Microsoft Windows responsible for representing graphical objects and transmitting them to output devices such as monitors and printers. It was superseded by DirectDraw API and later Direct2D API. Windows apps use Windows API to interact with GDI, for such tasks as drawing lines and curves, rendering fonts, and handling palettes. The Windows USER subsystem uses GDI to render such UI elements as window frames and menus. Other systems have components that are similar to GDI; for example: Mac OS has QuickDraw, and Linux and Unix have X Window System core protocol.

OpenType is a format for scalable computer fonts. Derived from TrueType, it retains TrueType's basic structure but adds many intricate data structures for describing typographic behavior. OpenType is a registered trademark of Microsoft Corporation.

Extensible Application Markup Language is a declarative XML-based language developed by Microsoft for initializing structured values and objects. It is available under Microsoft's Open Specification Promise.

<span class="mw-page-title-main">Windows Forms</span> Graphical user interface software library

Windows Forms (WinForms) is a free and open-source graphical (GUI) class library included as a part of Microsoft .NET, .NET Framework or Mono, providing a platform to write client applications for desktop, laptop, and tablet PCs. While it is seen as a replacement for the earlier and more complex C++ based Microsoft Foundation Class Library, it does not offer a comparable paradigm and only acts as a platform for the user interface tier in a multi-tier solution.

<span class="mw-page-title-main">Font rasterization</span> Process of converting text from vector to raster

Font rasterization is the process of converting text from a vector description to a raster or bitmap description. This often involves some anti-aliasing on screen text to make it smoother and easier to read. It may also involve hinting—information embedded in the font data that optimizes rendering details for particular character sizes.

<span class="mw-page-title-main">ClickOnce</span>

ClickOnce is a component of Microsoft .NET Framework 2.0 and later, and supports deploying applications made with Windows Forms or Windows Presentation Foundation. It is similar to Java Web Start for the Java Platform or Zero Install for Linux.

Desktop Window Manager is the compositing window manager in Microsoft Windows since Windows Vista that enables the use of hardware acceleration to render the graphical user interface of Windows.

Resolution independence is where elements on a computer screen are rendered at sizes independent from the pixel grid, resulting in a graphical user interface that is displayed at a consistent physical size, regardless of the resolution of the screen.

Windows Vista has many significant new features compared with previous Microsoft Windows versions, covering most aspects of the operating system.

<span class="mw-page-title-main">Microsoft Silverlight</span> Application framework for writing and running rich Internet applications

Microsoft Silverlight is a discontinued application framework designed for writing and running rich internet applications, similar to Adobe's runtime, Adobe Flash. While early versions of Silverlight focused on streaming media, later versions supported multimedia, graphics, and animation, and gave support to developers for CLI languages and development tools. Silverlight was one of the two application development platforms for Windows Phone, but web pages using Silverlight did not run on the Windows Phone or Windows Mobile versions of Internet Explorer, as there was no Silverlight plugin for Internet Explorer on those platforms.

XAML Browser Applications are Windows Presentation Foundation (.xbap) applications that are hosted and run 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 like opening a new network connection or saving a file to the computer disk and not all WPF functionality is available. The hosted environment is intended to protect the computer from malicious applications; however it can also run in full trust mode by the client changing the permission. Starting an XBAP from an HTML page is seamless. Although one perceives the application running in the browser, it actually runs in an out-of-process executable (PresentationHost.exe) managed by a virtual machine. In the initial release of .NET Framework 3.0, XBAPs only ran in Internet Explorer. With the release of .NET Framework 3.5 SP1, which includes an XBAP extension, they also run in Mozilla Firefox.

Direct2D is a 2D vector graphics application programming interface (API) designed by Microsoft and implemented in Windows 10, Windows 8, Windows 7 and Windows Server 2008 R2, and also Windows Vista and Windows Server 2008.

MapDotNet is a suite of geographic information system (GIS) software products developed by ISC that run on Microsoft Windows. The GIS software competes with ESRI and MapInfo GIS products. MapDotNet UX is the latest generation and consists of a set of WCF web services for rendering map images and tiles and for performing spatial analysis and editing. UX includes an SDK for developing rich interactive mapping applications on Microsoft Silverlight, Windows Presentation Foundation and HTML5. MapDotNet UX also includes an Extract, Transform & Load (ETL), map design and tile cache creation tool called Studio modeled after Microsoft's Expression series of products. The MapDotNet UX renderer is built on WPF and consumes spatial data from multiple sources including Shapefiles, PostGIS, ArcSDE, Oracle Spatial, SQL Azure, SQL Server 2008 R2 and SQL Server 2012.

Model–view–viewmodel (MVVM) is an architectural pattern in computer software that facilitates the separation of the development of the graphical user interface —be it via a markup language or GUI code—from the development of the business logic or back-end logic such that the view is not dependent upon any specific model platform.

Microsoft Silverlight is an application framework for writing and running rich web applications that was actively developed and marketed by Microsoft from 2007 to 2012. This is a technical overview of the platform's history.

Windows Runtime (WinRT) is a platform-agnostic component and application architecture first introduced in Windows 8 and Windows Server 2012 in 2012. It is implemented in C++ and officially supports development in C++, Rust/WinRT, Python/WinRT, JavaScript-TypeScript, and the managed code languages C# and Visual Basic .NET (VB.NET).

<span class="mw-page-title-main">FireMonkey</span>

FireMonkey is a cross-platform GUI framework developed by Embarcadero Technologies for use in Delphi, C++Builder or Python, using Object Pascal, C++ or Python to build cross platform applications for Windows, macOS, iOS, and Android. A 3rd party library, FMX Linux, enables the building of FireMonkey applications on Linux.

Windows UI Library is a user interface API that is part of the Windows Runtime programming model that forms the backbone of Universal Windows Platform apps for the Windows 8, Windows 8.1, Windows 10 and Windows Phone 8.1 operating systems. It enables declaring user interfaces using Extensible Application Markup Language (XAML) technology.

References

  1. "v8.0.0". github.com. 2023-11-14. Retrieved 2023-11-21.
  2. Nathan, Adam (2006). Windows Presentation Foundation Unleashed. Pearson Education. ISBN   9780132715621.
  3. dotnet-bot. "XAML Overview (WPF)". msdn.microsoft.com. Retrieved 31 March 2018.
  4. Sells, Chris; Griffiths, Ian (2007). Programming WPF: Building Windows UI with Windows Presentation Foundation. "O'Reilly Media, Inc.". ISBN   9780596554798.
  5. ".NET". Microsoft. Retrieved 31 March 2018.
  6. "Microsoft .NET Framework 3.0 Download". microsoft.com. Retrieved 31 March 2018.
  7. Silverlight Learning Resources. Silverlight.net. Retrieved on 2013-08-29.
  8. Martin, Jeff (4 December 2018). "Microsoft Open Sources WPF, WinForms, and WinUI". InfoQ. Retrieved 2018-12-06.
  9. Hanselman, Scott (4 December 2018). "Announcing WPF, WinForms, and WinUI are going Open Source" . Retrieved 2018-12-06.
  10. "Introducing Windows Presentation Foundation". msdn.microsoft.com. Retrieved 31 March 2018.
  11. 1 2 "What's New in WPF 3.5? Here's Fifteen Cool Features..." Retrieved 2007-10-14.
  12. Graphics and Multimedia. Msdn.Microsoft.com. Retrieved on 2013-08-29.
  13. 1 2 3 4 "Animation overview". MSDN . Retrieved 2007-10-14.
  14. "Typography in Windows Presentation Foundation". msdn.microsoft.com. Retrieved 31 March 2018.
  15. dotnet-bot. "ClearType Overview". msdn.microsoft.com. Retrieved 31 March 2018.
  16. "Disable Antialiasing". social.msdn.microsoft.com. Retrieved 31 March 2018.
  17. "My first thoughts on WPF with VS 2008 RTM and a few questions". social.msdn.microsoft.com. Retrieved 31 March 2018.
  18. WPF 4 (VS 2010 and .NET 4.0 Series) - ScottGu's Blog. Weblogs.asp.net. Retrieved on 2013-08-29.
  19. Xansky. "UI Automation Overview". msdn.microsoft.com. Retrieved 31 March 2018.
  20. MacDonald, Matthew (2010). Pro WPF in VB 2010: Windows Presentation Foundation in .NET 4. Apress. ISBN   9781430272403.
  21. 1 2 3 Chris Anderson. "MIL information" . Retrieved 2007-10-14.
  22. 1 2 3 4 5 6 7 "WPF Architecture". MSDN . Retrieved 2007-10-14.
  23. Schechter, Greg (June 9, 2006). "How underlying WPF concepts and technology are being used in the DWM". MSDN Blogs. Microsoft . Retrieved 2015-07-27.
  24. "Create a WPF application in Visual Studio". docs.microsoft.com.
  25. "WPF Architecture". docs.microsoft.com.
  26. 1 2 "Threading Model". MSDN . Retrieved 2007-10-14.
  27. "The Layout System". MSDN . Retrieved 2007-10-14.
  28. Retrieved from http://www.microsoft.com/en-au/download/details.aspx?id=23072.
  29. Wille, Christoph. "SharpDevelop @ic#code". icsharpcode.net. Retrieved 31 March 2018.
  30. Rich Application Development Tool/Declarative Programming Environment | PowerBuilder - Sybase Inc. Sybase.com. Retrieved on 2013-08-29.
  31. "WPF controls for your modern Desktop Apps". www.syncfusion.com. Retrieved 2021-02-17.
  32. "Avalonia XPF - Cross-Platform WPF". www.avaloniaui.net. Retrieved 2023-02-26.
  33. "NET Framework Assistant Blocked to Disarm Security Vulnerability" . Retrieved 2009-10-17.
  34. "Firefox Add-ons to Support .NET Application Deployment" . Retrieved 2010-09-07.
  35. 1 2 "Xbap plugin for firefox in Windows 7" . Retrieved 2010-09-29.
  36. "The Official Microsoft ASP.NET Site". The Official Microsoft ASP.NET Site. Retrieved 31 March 2018.
  37. "Silverlight 1.0 Released and Silverlight for Linux Announced" . Retrieved 2007-09-05.

Bibliography