Windows Presentation Foundation
   HOME

TheInfoList



OR:

Windows Presentation Foundation (WPF) is a
free and open-source Free and open-source software (FOSS) is software available under a Software license, license that grants users the right to use, modify, and distribute the software modified or not to everyone free of charge. FOSS is an inclusive umbrella term ...
user interface In the industrial design field of human–computer interaction, a user interface (UI) is the space where interactions between humans and machines occur. The goal of this interaction is to allow effective operation and control of the machine fro ...
framework for
Windows Windows is a Product lining, product line of Proprietary software, proprietary graphical user interface, graphical operating systems developed and marketed by Microsoft. It is grouped into families and subfamilies that cater to particular sec ...
-based desktop applications. WPF applications are based in
.NET The .NET platform (pronounced as "''dot net"'') is a free and open-source, managed code, managed computer software framework for Microsoft Windows, Windows, Linux, and macOS operating systems. The project is mainly developed by Microsoft emplo ...
, and are primarily developed using C# and XAML. Originally developed by
Microsoft Microsoft Corporation is an American multinational corporation and technology company, technology conglomerate headquartered in Redmond, Washington. Founded in 1975, the company became influential in the History of personal computers#The ear ...
, WPF was initially released as part of .NET Framework 3.0 in 2006. In 2018, Microsoft released WPF as
open source Open source is source code that is made freely available for possible modification and redistribution. Products include permission to use and view the source code, design documents, or content of the product. The open source model is a decentrali ...
under the
MIT License The MIT License is a permissive software license originating at the Massachusetts Institute of Technology (MIT) in the late 1980s. As a permissive license, it puts very few restrictions on reuse and therefore has high license compatibility. Unl ...
. WPF's design and its layout language XAML have been adopted by multiple other UI frameworks, such as UWP, .NET MAUI, and Avalonia.


Overview

WPF employs XAML, an
XML Extensible Markup Language (XML) is a markup language and file format for storing, transmitting, and reconstructing data. It defines a set of rules for encoding electronic document, documents in a format that is both human-readable and Machine-r ...
-based language, to define and link various interface elements, and uses C# to define program behavior. WPF applications are deployed as standalone desktop programs. WPF supports a number of common
user interface In the industrial design field of human–computer interaction, a user interface (UI) is the space where interactions between humans and machines occur. The goal of this interaction is to allow effective operation and control of the machine fro ...
elements, such as 2D/3D rendering, fixed and adaptive
documents A document is a written, drawn, presented, or memorialized representation of thought, often the manifestation of non-fictional, as well as fictional, content. The word originates from the Latin ', which denotes a "teaching" or "lesson": ...
,
typography Typography is the art and technique of Typesetting, arranging type to make written language legibility, legible, readability, readable and beauty, appealing when displayed. The arrangement of type involves selecting typefaces, Point (typogra ...
,
vector graphics Vector graphics are a form of computer graphics in which visual images are created directly from geometric shapes defined on a Cartesian plane, such as points, lines, curves and polygons. The associated mechanisms may include vector displ ...
, runtime
animation Animation is a filmmaking technique whereby still images are manipulated to create moving images. In traditional animation, images are drawn or painted by hand on transparent celluloid sheets to be photographed and exhibited on film. Animati ...
, 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 Windows is a Product lining, product line of Proprietary software, proprietary graphical user interface, graphical operating systems developed and marketed by Microsoft. It is grouped into families and subfamilies that cater to particular sec ...
since
Windows Vista Windows Vista is a major release of the Windows NT operating system developed by Microsoft. It was the direct successor to Windows XP, released five years earlier, which was then the longest time span between successive releases of Microsoft W ...
and Windows Server 2008. At the Microsoft Connect event on December 4, 2018,
Microsoft Microsoft Corporation is an American multinational corporation and technology company, technology conglomerate headquartered in Redmond, Washington. Founded in 1975, the company became influential in the History of personal computers#The ear ...
announced releasing WPF as open source project o
GitHub
It is released under the
MIT License The MIT License is a permissive software license originating at the Massachusetts Institute of Technology (MIT) in the late 1980s. As a permissive license, it puts very few restrictions on reuse and therefore has high license compatibility. Unl ...
. Windows Presentation Foundation has become available for projects targeting the
.NET The .NET platform (pronounced as "''dot net"'') is a free and open-source, managed code, managed computer software framework for Microsoft Windows, Windows, Linux, and macOS operating systems. The project is mainly developed by Microsoft emplo ...
software framework, however, the system is not cross-platform and is still available only on Windows.


Code examples

In WPF, screens and other UI elements are defined using a pair of files: a XAML file and an associated C# file with the extension .xaml.cs, often referred to as a "code-behind". The XAML file declaratively defines the layout, contents and other properties of the UI element, while the C# file allows exposure of code entry points for interactivity. A basic example of an interactive Hello, World! program could be created like so: MainWindow.xaml: MainWindow.xaml.cs: using System.Windows; namespace WpfExample In the above example, a UI element called MainWindow is declared as a subclass of the built-in Window class. The XAML file defines the layout, which in this example is a vertical collection of controls - a textblock outlining instructions to the user, a textbox for the user to type their name, a button to submit, and a results text block. When the button is clicked, the method SubmitButton_Click is called, which is defined in the .xaml.cs file. This function updates the final textblock to contain a message greeting the user, addressing them by their submitted name.


Features


Media and Graphics

WPF supports most modern media types, including vector and raster images, audio, video, and can support both 2D and 3D rendering. It also supports implementing graphical effects on visual elements, such as HLSL pixel shaders and built-in effects such as blurs and drop shadows. WPF mainly relies on vector graphics, which allows most controls and elements to be scaled without loss in quality or pixelization.


Data binding

WPF employs data binding, a technique of propagating changes between user interface elements and the object model of the program. For instance, a textblock defined in XAML could bind its contents to a string property stored on a C# object in the following way: public class ExampleViewModel This would make the textblock display the value of the Username property. The direction data binding happens is configurable - it can be defined to go UI-to-source (eg. text entered into a textbox being propagated to a bound string property in code), or source-to-UI (eg. a visual clock being updated to display the current time stored in code), or bi-directional. Data binding doesn't have any restrictions on types, and it is possible to bind structs, classes, or collections. Converters can be used to transpose the values and types being used during binding - for example, binding a textbox to a DateTime property, but using a converter to display the time as a formatted localised date string. Most properties on built-in controls can be databound, and custom-made controls can create bindable properties by defining Dependency Properties. MVVM, the architectural pattern encouraged by Microsoft for WPF developers, relies heavily on data binding.


Styles and templates

Using templates and styles, developers can define the visuals and structure of UI elements. A style is a combination of property settings that can be applied to a UI element with a single property attribute. For example, a "blue radio button" style could be created and then be reused on any number of radio button controls throughout the program. Styles can alter collections of properties of controls, but are not not intended for significant structural changes. Templates are a mechanism for defining alternative UI for portions of a WPF application. There are several template types available in WPF for different scenarios, but they all have the general purpose of defining the contents, layout and structure of a UI element.


Animations

In WPF, many visual properties can be animated. This is exposed through dependency properties, which is the same underlying system that data binding relies on. WPF animations are time-based, as opposed to frame-based. 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 Double, The Double or Dubble may refer to: Mathematics and computing * Multiplication by 2 * Double precision, a floating-point representation of numbers that is typically 64 bits in length * A double number of the form x+yj, where j^2=+1 * A ...
) is done with the DoubleAnimation class. Animations can be grouped into Storyboards, which are the primary way to start, stop, pause and otherwise manipulate animations.


Documents and Text

WPF natively supports paginated documents. It provides the DocumentViewer class, which is for reading fixed layout documents. The FlowDocumentReader class offers different view modes such as per-page or scrollable and also reflows text if the viewing area is resized. It supports both the
XML Paper Specification Open XML Paper Specification (also referred to as OpenXPS) is an open specification for a page description language and a fixed-document format. Microsoft developed it as the XML Paper Specification (XPS). In June 2009, Ecma International adopte ...
and Open Packaging Conventions. WPF includes a number of text rendering features, including OpenType, TrueType, and OpenType CFF ( Compact Font Format) fonts. This means that WPF can support a wide number of text features, including ligatures, old-style numerals, swash variants,
fraction A fraction (from , "broken") represents a part of a whole or, more generally, any number of equal parts. When spoken in everyday English, a fraction describes how many parts of a certain size there are, for example, one-half, eight-fifths, thre ...
,
superscript A subscript or superscript is a character (such as a number or letter) that is set slightly below or above the normal line of type, respectively. It is usually smaller than the rest of the text. Subscripts appear at or below the baseline, wh ...
and subscript,
small caps In typography, small caps (short for small capitals) are grapheme, characters typeset with glyphs that resemble uppercase letters but reduced in height and weight close to the surrounding lowercase letters or text figures. Small caps are used i ...
, ruby characters, glyph substitution, multiple baselines, and
kerning In typography, kerning is the process of adjusting the spacing between Character (symbol), characters in a Typeface#Proportion, proportional font, usually to achieve a visually pleasing result. Kerning adjusts the space between individual le ...
. WPF handles texts in
Unicode Unicode or ''The Unicode Standard'' or TUS is a character encoding standard maintained by the Unicode Consortium designed to support the use of text in all of the world's writing systems that can be digitized. Version 16.0 defines 154,998 Char ...
, 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 '. 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,
hyphen The hyphen is a punctuation mark used to join words and to separate syllables of a single word. The use of hyphens is called hyphenation. The hyphen is sometimes confused with dashes (en dash , em dash and others), which are wider, or with t ...
ation, 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 technology, such as sub-pixel positioning, natural advance widths, Y-direction anti-aliasing, hardware-accelerated 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.


Interoperability

Windows Forms features are possible through the use of the ElementHost and WindowsFormsHost classes. To enable the use of WinForms, the developer executes this from their WPF C# code: System.Windows.Forms.Integration.WindowsFormsHost.EnableWindowsFormsInterop(); WPF programs, via the P/Invoke feature of the CLR, can access native functionality such calling functions from Windows libraries. This allows the ability to communicate and operate other parts of the operating system, including unmanaged libraries.


Alternative input and accessibility

WPF supports Windows Ink for pen-based input, and multi-touch input on
Windows 7 Windows 7 is a major release of the Windows NT operating system developed by Microsoft. It was Software release life cycle#Release to manufacturing (RTM), released to manufacturing on July 22, 2009, and became generally available on October 22, ...
and above. It also supports Microsoft UI Automation to allow developers to create accessible interfaces, and to expose the UI to automated test frameworks.


XAML

Following the success of
markup language A markup language is a Encoding, text-encoding system which specifies the structure and formatting of a document and potentially the relationships among its parts. Markup can control the display of a document or enrich its content to facilitate au ...
s for web development, WPF introduced eXtensible Application Markup Language ( XAML; ), which is based on
XML Extensible Markup Language (XML) is a markup language and file format for storing, transmitting, and reconstructing data. It defines a set of rules for encoding electronic document, documents in a format that is both human-readable and Machine-r ...
. XAML is designed as a more efficient method of developing application user interfaces. XAML is a declarative language, meaning the developer (or designer) describes the behavior and integration of components without the use of
procedural programming Procedural programming is a programming paradigm, classified as imperative programming, that involves implementing the behavior of a computer program as Function (computer programming), procedures (a.k.a. functions, subroutines) that call each o ...
. 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 The .NET platform (pronounced as "''dot net"'') is a free and open-source, managed code, managed computer software framework for Microsoft Windows, Windows, Linux, and macOS operating systems. The project is mainly developed by Microsoft emplo ...
language ( C#, VB.NET). The XAML code can ultimately be compiled into a managed assembly in the same way all .NET languages are.


Deployment

WPF applications are Windows-only standalone desktop
executable In computer science, executable code, an executable file, or an executable program, sometimes simply referred to as an executable or binary, causes a computer "to perform indicated tasks according to encoded instruction (computer science), in ...
s. Historically, WPF supported compiling to XBAP, a file format intended to be shown in
web browser A web browser, often shortened to browser, is an application for accessing websites. When a user requests a web page from a particular website, the browser retrieves its files from a web server and then displays the page on the user's scr ...
s via a NPAPI plugin, but NPAPI and XBAP support was phased out of support by browsers, and XBAP compilation is now no longer included for WPF for .NET.


Usage and influence

WPF is used to develop Visual Studio, Microsoft's flagship IDE, and was used for developing Microsoft Expression Blend. WPF and its layout language, XAML, have influenced multiple other UI frameworks. Silverlight (codenamed WPF/E - WPF Everywhere), released in 2007, is a deprecated cross-browser browser plugin. Silverlight had a WPF-based implementation, including using XAML for layouting, that supported video, vector graphics, and animations. Using add-ons, it was supported on Mozilla Firefox, Internet Explorer 6 and above,
Google Chrome Google Chrome is a web browser developed by Google. It was first released in 2008 for Microsoft Windows, built with free software components from Apple WebKit and Mozilla Firefox. Versions were later released for Linux, macOS, iOS, iPadOS, an ...
42 and below and Apple Safari. Microsoft encouraged developers to stop using Silverlight in 2015, and support was officially ended in 2021. After becoming open source in 2018, WPF inspired the development of Avalonia, an open-source .NET cross-platform XAML-based UI framework, distributed under the
MIT License The MIT License is a permissive software license originating at the Massachusetts Institute of Technology (MIT) in the late 1980s. As a permissive license, it puts very few restrictions on reuse and therefore has high license compatibility. Unl ...
. While WPF only is intended for Windows, Avalonia also supports builds for web (via WebAssembly),
MacOS macOS, previously OS X and originally Mac OS X, is a Unix, Unix-based operating system developed and marketed by Apple Inc., Apple since 2001. It is the current operating system for Apple's Mac (computer), Mac computers. With ...
, Android, iOS, and
Linux Linux ( ) is a family of open source Unix-like operating systems based on the Linux kernel, an kernel (operating system), operating system kernel first released on September 17, 1991, by Linus Torvalds. Linux is typically package manager, pac ...
. Avalonia's name references WPF's in-development codename ("Avalon"), and markets itself as "a spiritual successor to WPF". Avalonia is currently used in tools made by Unity,
GitHub GitHub () is a Proprietary software, proprietary developer platform that allows developers to create, store, manage, and share their code. It uses Git to provide distributed version control and GitHub itself provides access control, bug trackin ...
and JetBrains. OpenSilver is framework designed to migrate WPF solutions to web using WebAssembly. OpenSilver 3.1, released in December 2024, included a XAML designer for use in Visual Studio Code. XAML, which was first designed for WPF, has been adopted for other similar Microsoft-developed UI libraries, such as UWP, designed for
Windows 10 Windows 10 is a major release of Microsoft's Windows NT operating system. The successor to Windows 8.1, it was Software release cycle#Release to manufacturing (RTM), released to manufacturing on July 15, 2015, and later to retail on July 2 ...
,
Windows 11 Windows 11 is a version of Microsoft's Windows NT operating system, released on October 5, 2021, as the successor to Windows 10 (2015). It is available as a free upgrade for devices running Windows 10 that meet the #System requirements, Windo ...
,
Xbox One The Xbox One is a home video game console developed by Microsoft. Announced in May 2013, it is the successor to Xbox 360 and the third console in the Xbox#Consoles, Xbox series. It was first released in North America, parts of Europe, Austra ...
and Xbox Series S/X applications, and .NET MAUI (formerly Xamarin.Forms), designed for creating cross-platform native Android and iOS apps.


Development

Developers of WPF applications typically use Microsoft Visual Studio. Visual Studio contains a combination XAML editor and WPF visual designer, beginning with Visual Studio 2008. Prior to Visual Studio 2008, the WPF designer add-in, codenamed Cider, was the original release of a WYSIWYG editor for creating WPF windows, pages, and user controls. It was available for Visual Studio 2005 as a ''Visual Studio 2005 extensions for .NET Framework 3.0 CTP'' for the initial release of WPF. Visual Studio is not strictly required to develop WPF projects, as solutions can be built in the command line using MSBuild. Microsoft 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 is a bitmap and 2D-vector graphics tool for exporting to XAML.


References


Bibliography

* Adam Nathan: ''Windows Presentation Foundation Unleashed (WPF)'', December 21, 2006, Sams Publishing, * Chris Anderson: ''Essential Windows Presentation Foundation (WPF)'', April 11, 2007, Addison-Wesley, * Chris Sells, Ian Griffiths: ''Programming WPF'', August 28, 2007, O'Reilly Media, * Arlen Feldman, Maxx Daymon: ''WPF in Action with Visual Studio 2008'', November 21, 2008, Manning Publications,


External links


MSDN Library: Windows Presentation Foundation

Rich typography with Windows Presentation Foundation

Windows Presentation Foundation User Education
{{Authority control .NET terminology 2006 software Formerly proprietary software Free and open-source software Presentation Foundation Microsoft free software Microsoft Windows multimedia technology Software using the MIT license Widget toolkits Windows-only free software