What Is WPF (2024)

WPF, stands for Windows Presentation Foundation is a development framework and a sub-system of .NET Framework. WPF is used to build Windows client applications that run on Windows operating system. WPF uses XAML as its frontend language and C# as its backend languages.

WPF was introduced as a part of .NET Framework 3.0 as the Windows library to build Windows client apps and the next generation of Windows Forms. The current version of WPF is 4.5.

WPF is the engine that is responsible for creating, displaying, and manipulating user-interfaces, documents, images, movies, and media in Windows 7 and later Windows operating systems. WPF is a set of libraries that have all functionality you need to build, run, execute, and manage Windows client applications.

Learn more about WPF here: Learn WPF

WPF and XAML

XAML is a new descriptive programming language developed by Microsoft to write user interfaces for next-generation managed applications. XAML is used to build user interfaces for Windows and Mobile applications that use Windows Presentation Foundation (WPF), UWP, and Xamarin Forms.

The purpose of XAML is simple, to create user interfaces using a markup language that looks like XML. Most of the time, you will be using a designer to create your XAML but you’re free to directly manipulate XAML by hand.

XAML uses the XML format for elements and attributes. Each element in XAML represents an object which is an instance of a type. The scope of a type (class, enumeration etc.) is defined a namespace that physically resides in an assembly (DLL) of the .NET Framework library.

Similar to XML, a XAML element syntax always starts with an open angle bracket (<) and ends with a close angle bracket (>). Each element tag also has a start tag and an end tag. For example, a Button object is represented by the <Button> object element. The following code snippet creates a Button object element.

<Button></Button>

Alternatively, you can use a self-closing format to close the bracket.

<Button />

Here is a free Ebook download on XAML: Programming XAML

WPF and C#

While XAML is used to build user interfaces in WPF, C# is used as the code-behind languages in WPF. While Windows and their controls are created in XAML at design-time, they can also be created at runtime using C# language.

C# is also used to write all events programming and business logic. All actions, events, and rendering is done in the code behind C# code.

Here is a free C# programming book: C# Programming for Beginners

WPF Resources

WPF supports two types of resources, static and dynamic.

Static Resources: A Static Resource will be resolved and assigned to the property during the loading of the XAML that occurs before the application is actually run. It will only be assigned once and any changes to the resource dictionary is ignored.

Dynamic Resources: A Dynamic Resource assigns an Expression object to the property during loading but does not actually lookup the resource until runtime when the Expression object is asked for the value. This defers looking up the resource until it is needed at runtime. A good example would be a forward reference to a resource defined later on in the XAML. Another example is a resource that will not even exist until runtime. It will update the target if the source's resource dictionary is changed.

WPF Styles

Style is a way to group similar properties in a single Style object and apply to multiple objects. The Style element in XAML represents a style. A Style is usually added to the resources of a FrameworkElement. The x:Key is the unique key identifier of the style.

Here is a detailed tutorial: Styles in WPF

Templates in WPF

Templates are an integral part of user interface design in WPF. This article explains templates, their types and how to use them in Windows applications.

WPF has the following three types of templates, Control Template, Items Panel Template, and Data Template.

Here is detailed tutorial: Templates in WPF

Data Binding in WPF

Binding allows you to link a source object to some control. There are the following two types of bindings:

  • One-Way Binding: Binds a source to the interface.
  • Two-Way Binding: Binds a source to the interface and back to the source.

INotifyPropertyChanged interface allows sources to interact with the interface and update it as the values change.

  • To bind an object or a list to an element you must set the DataContext property.
  • It is possible to bind an object or a list of objects and you can bind one element to another.
  • To customize how bound data will be displayed you can set the DataTemplate from a control.
  • It is possible to set Data Converters to convert the source type to another type.

Here is a detailed tutorial on Data Binding in WPF: Data Binding in WPF

Triggers in WPF

Triggers are used to perform certain actions when a specified condition is fulfilled. Triggers are used to create visual effects on controls and framework elements. Triggers are parts of styles and are always defined inside a style.

Types of Triggers

Basically, there are 3 types of triggers, they are:

  1. Property Trigger
  2. Data Trigger
  3. Event Trigger

Here is a detailed tutorial: Triggers in WPF

Media in WPF

WPF has two classes to work with audio, video and video with audio - MediaElement and MediaPlayer. The MediaElement is a part of XAML UIElement and is supported by both XAML and WPF code behind but MediaPlayer is available in WPF code behind only.

Here is a detailed tutorial: Media Player in WPF

Charting in WPF

WPF supports common charts including line, bar, curve and others.

Here is a detailed tutorial: Charting in WPF

WPF Controls

WPF has a set of rich UI controls. These controls support visual actions such as drag and drop, setting properties and events, data binding, and setting up resources and templates.

Here are hundreds of WPF controls and code samples: Learn WPF

WPF DatePicker Control

A DatePicker control is used to create a visual DatePicker that let user to pick a date and fire an event on the selection of the date. This article demonstrates how to create and use a DatePicker control in WPF with the help of XAML and C#.

Here is a detailed tutorial: WPF DatePicker

WPF DockPanel

A Dock Panel is used to dock child elements in the left, right, top, and bottom positions of the relative elements. The position of child elements is determined by the Dock property of the respective child elements and the relative order of those child elements. The default value of Dock property is left. The Dock property is of type Dock enumeration that has Left, Right, Top, and Bottom values.

Here is a detailed tutorial: DockPanel in WPF

WPF ListBox

The XAML ListBox element represents a ListBox control.

1. <ListBox></ListBox>

The Width and Height properties represent the width and the height of a ListBox. The Name property represents the name of the control, which is a unique identifier of a control. The Margin property tells the location of a ListBox on the parent control. The HorizontalAlignment and VerticalAlignment properties are used to set horizontal and vertical alignments.

Learn more here: WPF ListBox

WPF ComboBox

A ComboBox control is an items control that works as a ListBox control but only one item from the collection is visible at a time and clicking on the ComboBox makes the collection visible and allows users to pick an item from the collection. Unlike a ListBox control, a ComboBox does not have multiple item selection. A ComboBox control is a combination of three controls - A Button, a Popup, and a TextBox. The Button control is used to show or hide available items and Popup control displays items and lets user select one item from the list. The TextBox control then displays the selected item.

Learn more here: WPF ComboBox

WPF MessageBox

The MessageBox class in WPF represents a modal message box dialog, which is defined in the System.Windows namespace. The Show static method of the MessageBox is the only method that is used to display a message box. The Show method returns a MessageBoxResult enumeration that has the values None, OK, Cancel, Yes, and No. We can use MessageBoxResult to determine what button was clicked on a MessageBox and take an appropriate action.

Learn more here: MessageBox in WPF

WPF DataGrid

DataGrid element represents WPF DataGrid control in XAML.

1. <DataGrid />

When you drag and drop a DataGrid control from Toolbox to your designer, position the control, this action adds the following code to XA

The Width and Height properties represent the width and the height of a DataGrid. The Name property represents the name of the control, which is a unique identifier of a control. The Margin property sets the margin of placement of DataGrid on the window.

Learn more here: DataGrid in WPF

WPF ProgressBar

The ProgressBar tag in XAML represents a WPF ProgressBar control.

1. <ProgressBar></ProgressBar>

The Width and Height properties represent the width and the height of a ProgressBar. The Name property represents the name of the control, which is a unique identifier of a control. The Margin property tells the location of a ProgressBar on the parent control. The HorizontalAlignment and VerticalAlignment properties are used to set horizontal and vertical alignments.

Learn more here: WPF ProgressBar

WPF TreeView

A TreeView represents data in a hierarchical view in a parent child relationship where a parent node can be expanded or collapsed. The left side bar of Windows Explorer is an example of a TreeView.

In this tutorial, we will create a WPF application that will add and delete a TreeView items dynamically. The UI looks like the following where anything entered in the TextBox will be added to the TreeView as a child node.

Learn more here: TreeView in WPF

WPF Interview Questions

Are you going for a WPF interview? Here is a list if top WPF interview questions and their answers.

What Is WPF (2024)

FAQs

What is WPF used for? ›

Windows Presentation Foundation (WPF) is a UI framework that creates desktop client applications. The WPF development platform supports a broad set of application development features, including an application model, resources, controls, graphics, layout, data binding, documents, and security.

Does anyone still use WPF? ›

While not much chatter or excitement for what is no longer a new technology, WPF still has a lot of demand in internal and business-critical applications.

Is WPF .NET or .NET core? ›

NET Core WPF is a . NET Foundation project. See the . NET home repo to find other .

Is WPF a programming language? ›

WPF, stands for Windows Presentation Foundation is a development framework and a sub-system of . NET Framework. WPF is used to build Windows client applications that run on Windows operating system. WPF uses XAML as its frontend language and C# as its backend languages.

What has replaced WPF? ›

What is the best alternative for WPF? It's the VCL. VCL – an abbreviation of Visual Component Library – is a set of visual tools effective for the rapid development of Windows applications. It uses the easy to learn yet modern, powerful Delphi language for the program code and to drive the applications.

Is WPF still in demand? ›

However, some industries still rely on WPF concepts and tools like XAML & MVVM to develop futuristic web, mobile, and desktop applications. None of Microsoft's GUI frameworks ever really die. And there is no indication of a WPF support end date anywhere.

Is WPF still relevant 2024? ›

NET developers, the Windows Presentation Foundation (WPF) remains one of the best tools for building powerful desktop applications. As we get closer and closer to 2024, Let's take this opportunity to explore some of the most important best practices that will have you using WPF more effectively!

Why use WPF over Windows Forms? ›

WPF uses a more modern approach to layout that is based on XAML, while WinForms uses a more traditional approach that is based on forms and controls. This means that WPF provides more flexibility and control over the layout and appearance of the UI, while WinForms is simpler to use for basic UI design.

When was WPF deprecated? ›

WPF is not deprecated, and it remains a solid choice for building Windows desktop applications with rich user interfaces. Microsoft has continued to invest in WPF with updates and improvements, so it's a reliable choice for traditional Windows applications.

Is WPF deprecated? ›

According to the documentation Overview - Product end of support, there are no plans to remove wpf. So it will be supported.

Can I use WPF with .NET Core? ›

All Syncfusion WPF and WinForms components support . NET Core 3.0. From the recent 17.2 release, you can run existing WPF and WinForms product showcase demos in both . NET Core and .

Is WPF in .NET 5? ›

NET 5 gave us an updated version of Windows Presentation Foundation (WPF). Unlike Web Forms or the Windows Communication Foundation (WCF), Microsoft brought this . NET Framework technology into . NET5+ (.

Are WinForms dead? ›

Winforms and WPF are still available only on Windows platform. There's a new version of . NET each year around November—. NET 7 is the current version, but .

Can I use WPF with Python? ›

It is certainly possible to write an Iron Python/WPF program - I've done just that. Probably your solution could also include classes written in C# - that is something I haven't tried. Good luck!

What was WPF previously known as? ›

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.

Why we use WPF in C#? ›

Library of WPF provides the functionality through which we can build, run, execute, and through the WPF library, we can manage all the Windows Client Applications. WPF employs XAML, which is an XML based language. XML is used to define and link the various elements.

Why use WPF over Windows forms? ›

WPF uses a more modern approach to layout that is based on XAML, while WinForms uses a more traditional approach that is based on forms and controls. This means that WPF provides more flexibility and control over the layout and appearance of the UI, while WinForms is simpler to use for basic UI design.

Why use WPF over WinForms? ›

While WinForms remains in use today, WPF offers a more contemporary and visually appealing UI framework, constructed on the foundation of DirectX. It's fundamentally different from WinForms in that it doesn't rely on native Windows controls in most cases.

Why we use WPF instead of Windows forms? ›

Conclusion. Winforms vs WPF both are mainly used for the same purpose for developing and designing windows applications, but WPF can be used for the web application. The difference between them is scalability, performance as WPF can render fast compared to windows forms, complexity, and support.

Top Articles
Latest Posts
Article information

Author: Fredrick Kertzmann

Last Updated:

Views: 5952

Rating: 4.6 / 5 (66 voted)

Reviews: 89% of readers found this page helpful

Author information

Name: Fredrick Kertzmann

Birthday: 2000-04-29

Address: Apt. 203 613 Huels Gateway, Ralphtown, LA 40204

Phone: +2135150832870

Job: Regional Design Producer

Hobby: Nordic skating, Lacemaking, Mountain biking, Rowing, Gardening, Water sports, role-playing games

Introduction: My name is Fredrick Kertzmann, I am a gleaming, encouraging, inexpensive, thankful, tender, quaint, precious person who loves writing and wants to share my knowledge and understanding with you.