windows presentation foundation form

This device is not currently supported for these products.

windows presentation foundation form

Windows Presentation Foundation

WPF, .NET platform and Visual Studio enable you to develop data-centric, modern line of business applications

  • Community 2022
  • Professional 2022
  • Enterprise 2022

.NET Framework graphic

.NET Framework

Power, security, and flexibility.

.NET Framework for desktop provides a comprehensive and consistent programming model for building data-centric applications that enable seamless and secure communication.

Rich, productive, extensible

Windows Presentation Foundation (WPF) and XAML combine into a rich presentation system for building Windows desktop applications with visually stunning user experiences that incorporate UI, media, and complex business models. Rapidly develop enterprise-class line of business applications with a comprehensive set of features like controls, data binding, animation, styles, templates and more.

Code (1)

IntelliSense, navigation, refactoring

Enhance your developer productivity with advanced syntax highlighting, IntelliSense code completion, and intuitive source navigation in the code editor built on the .NET Compiler Platform (“Roslyn “) . Optimize and maintain your code-base with powerful refactoring and duplicate code detection tools.

Professional, sophisticated experiences

Create engaging user interfaces for Windows Desktop Applications with Blend for Visual Studio, the premier professional design tool for XAML applications. Build beautiful transitions and visualizations using Blend’s full suite of vector drawing tools, powerful template editing features, real-time animation, visual state management and more.

Design (1)

Azure, Office 365, Salesforce and more

Easily integrate with cloud services like Azure, Salesforce and Office 365 with the Visual Studio Services Manager for Connected Services. Seamlessly manage your servers, services and databases with features like Server Explorer and Data Sources.

Debug and analyze

Troubleshoot, diagnose, fix.

Streamline your development experience with first class debugging features like IntelliTrace, Code execution control and inspection, UI debugging tools for XAML, and a great experience for understanding and resolving Exceptions.

windows presentation foundation form

Measure, identify, improve

Optimize your WPF applications by using tools like CPU Usage, Memory Usage, GPU Usage and App Timeline in the Performance and Diagnostics hub. Identify bottlenecks and improve your performance with a scenario-centric view of resource usage in your application.

Validate, automate, manage

Adopt testing practices such as manual, automated, exploratory and load testing with Visual Studio and Team Foundation Server. Easily automate the process of building, deploying, and running tests in your lab environment with Visual Studio’s Lab Management tools.

test case

Package, publish, update

Create packages for Microsoft Windows Installer using the Visual Studio Setup Projects. Build and publish self-updating applications using Visual Studio’s support for ClickOnce .

Vibrant ecosystem

Open source, controls, frameworks, and tools.

Engage with a passionate developer community and quickly adopt established and emerging patterns and practices with a large number of third-party and Open Source libraries. The community is further bolstered by the presence of reputed control and tool vendors building extensive sets of components and controls for the platform.

Visual Studio Community 2022

Free, fully-featured IDE for students, open-source and individual developers

Visual Studio Professional 2022

Professional developer tools, services, and subscription benefits for small teams

Visual Studio Enterprise 2022

End-to-end solution to meet demanding quality and scale needs of teams of all sizes

The following navigation has top level toggles that can be engaged with by focusing on them and pressing the enter key. Their respective sub-navigation can then be navigated through with the tab key. Upon reaching the last node in the sub-navigation the next top level node will be focused if there is one.

Windows Presentation Foundation (WPF)

Windows Presentation Foundation (WPF)

NDepend Blog

Improve your .NET code quality with NDepend

WPF vs WinForms – Making the Right Decision in 2024

Share this:.

windows presentation foundation form

If you’re a developer faced with the decision of selecting between Windows Presentation Foundation ( WPF) and Windows Forms ( WinForms ) commonly referred to as WPF vs WinForms , you may be eager to understand the distinctions between these two UI frameworks . In this comprehensive guide, we will offer an in-depth comparison of WPF and WinForms. We will shed light on their prominent differentiating factors and shared characteristics.

Introduction to Windows Presentation Foundation (WPF) and Windows Forms (WinForms)

WinForms and WPF are two different UI frameworks built by Microsoft for creating desktop applications in the Microsoft .NET ecosystem. Let’s break down the main points:

WinForms , introduced with .NET 1.0 in 2001, leans heavily on standard Windows OS controls . This technology offers a streamlined managed layer over the familiar forms and controls provided by the Win32/WinAPI . It essentially encapsulates native Windows elements like buttons, textboxes, data grids, and combo-boxes. This approach simplifies the development of conventional Windows applications, retaining their recognizable look and feel.

Windows Presentation Foundation ( WPF ) emerged as a UI framework for Windows desktop applications, introduced by Microsoft in 2006. It was developed to supplant Winforms, the primary UI framework for Windows desktop applications since 2002. 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. WPF applications are built using a vector-based rendering system . They are not limited to the traditional Win32 controls. Instead, WPF offers a rich set of controls that are highly customizable and can be styled and templated extensively.

Key Distinctions: WPF vs. WinForms

To summarize, the most fundamental difference between Winforms and WPF is that Winforms is built on top of standard Windows controls and WPF relies on DirectX for rendering . This looks like details but the implications of this difference are significant:

  • Customization and Design : WPF provides more extensive customization and design capabilities, enabling developers to create highly stylized and visually appealing applications. WinForms, while functional, may require more effort to achieve the same level of visual sophistication.
  • Resolution Independence : WPF applications are resolution-independent because they are vector-based. They can adapt to different screen sizes and resolutions more easily. WinForms, being tied to standard Windows controls, might have some challenges in this regard.
  • UI Responsiveness : WPF’s rendering model allows for more responsive and interactive user interfaces, including animations and effects, which can be more challenging to achieve in WinForms.
  • XAML : WPF uses Extensible Application Markup Language (XAML), a declarative language for defining user interfaces. This makes it easier to separate UI design from code and allows for a more designer-developer collaboration.
  • Multimedia Content: WPF offers native multimedia support, including audio, video, and animation, making it a versatile choice. In contrast, WinForms does necessitate the use of extra libraries or plugins to enable multimedia capabilities.
  • Drag-and-Drop : WinForms offers drag-and-drop functionality, but it’s generally more straightforward and may not provide the same level of customization as WPF. It is suitable for basic drag-and-drop scenarios.
  • Learning Curve : Transitioning from WinForms to WPF can involve a learning curve due to the fundamental differences in architecture and design. Developers familiar with standard Windows controls may need to adapt to WPF’s way of working.

WPF vs. WinForms: Which One Offers Superior Performance?

When it comes to developing high-performance desktop applications, the choice between Windows Presentation Foundation (WPF) and Windows Forms (WinForms) is pivotal. WPF’s modern architecture, leveraging hardware acceleration and vector-based rendering , often results in smoother animations and graphics . Its resolution independence also shines on high DPI displays and touch which is the norm nowadays.

WinForms, in contrast, is often acknowledged as a lightweight and high-performance UI framework . Although it may not deliver the visual sophistication of WPF, Winforms excels in offering responsive user interfaces , even on less powerful hardware.

Both frameworks are performant, but WPF excels in achieving seamless animations and enhanced graphic quality . WinForms, on the other hand, is an excellent choice when you aim to develop a lightweight and responsive UI application .

WPF vs. WinForms: A Comparison of Flexibility

In the realm of desktop application development, flexibility is a key consideration. Windows Presentation Foundation (WPF) and Windows Forms (WinForms) are two prominent options, each with distinct traits.

WPF, with its modern approach, offers a high degree of flexibility. Its extensible XAML-based architecture allows for creative and customized user interfaces. It’s particularly suited for applications requiring intricate designs and innovative user experiences.

On the other hand, WinForms, while less visually flexible, excels in Rapid Application Development (RAD) . WinForms provides a variety of standard controls for quick and straightforward UI development. Nevertheless, its capabilities may become constraining and less adaptable when aiming for more complex and sophisticated UI designs.

Choosing between the two depends on your project’s specific requirements and the balance between visual flair and development speed you seek.

WPF vs. WinForms: Cross-Platform Compatibility

Both technologies are inherently Windows-centric and not originally engineered for cross-platform compatibility. Since 2017 both WPF and Winforms can run upon the new .NET Core runtime, which in turn functions smoothly on Linux and MacOS.. It’s important to note that, despite these capabilities, WPF and WinForms haven’t received official porting to other platforms, and Microsoft currently has no announced plans to do so.

Winforms and mono

Let’s highlight that developers can create and debug WinForms applications on a Windows PC using Visual Studio . They can then transfer these applications to the ComfilePi. The mono .NET runtime can then execute these applications without the requirement for recompilation. However, it’s important to note that using the Mono runtime to run WinForms applications on Linux and MacOS is discouraged for two significant reasons:

A) .NET Core has entirely replaced Mono and is the preferred runtime due to its enhanced features and performance.

B) The Mono port of WinForms contains numerous unresolved bugs, and there are no plans to address these issues, making it an unreliable choice for production use.

WPF and Avalonia

When it comes to WPF, there has been a recent effort to port it to Avalonia UI , and more details can be found here . Although it’s still in its early stages and considered somewhat immature, this port shows promise for legacy WPF projects.

Developing Cross-Platform Desktop .NET Applications

In summary, if you’re starting a new desktop application from scratch with cross-platform compatibility in mind, we highly recommend exploring frameworks like Uno , Avalonia ,   and MAUI . These frameworks are purpose-built for cross-platform development and can provide a solid foundation for your project’s success.

WPF vs. WinForms: Notable Advantages

WPF Advantages over Winforms:

  • Modern Standards : WPF is a newer technology. It aligns with contemporary development standards and practices.
  • Microsoft Adoption : Microsoft has used WPF for major applications like Visual Studio, demonstrating its commitment to the framework’s ongoing support and development.
  • Hardware Acceleration : Utilizing hardware acceleration for GUI rendering, WPF delivers improved performance.
  • XAML for Design : The XAML markup language simplifies GUI creation and editing, facilitating collaboration between designers and developers. This allows for a clear separation of UI design and code.
  • Enhanced Flexibility : WPF offers greater flexibility, reducing the need to create or purchase additional controls.
  • Effective Data Binding : WPF features robust data binding capabilities, enabling a clean separation of data and layout.
  • Rich Data Visualization : WPF excels in data visualization, making it an excellent choice for applications that require complex charting, data-driven graphics, and dashboard-style interfaces.

WinForms Advantages over WPF:

  • Maturity and Stability : WinForms is a well-established technology with a long history of development and refinement. It has been thoroughly tested in various applications, proving its stability and reliability.
  • Simplified Design in Visual Studio : The Visual Studio designer experience for WinForms is often considered more user-friendly and polished compared to WPF. It offers a more straightforward and intuitive way to design user interfaces.
  • Abundant 3rd Party Controls : A wide array of third-party controls is readily available for WinForms, many of which are free or commercially accessible.
  • Ease of Adoption : WinForms can be a natural choice for developers transitioning from traditional Windows application development. Its familiarity can reduce the learning curve for those accustomed to Win32 development.
  • Swift Development : WinForms is well-suited for rapid application development, making it an efficient choice for projects with tight deadlines and straightforward UI requirements.

In conclusion, the choice between WPF and WinForms hinges on carefully assessing your project’s unique needs.

  • WPF excels in delivering modern, visually compelling user interfaces and cross-platform potential.
  • WinForms offers stability, efficient development, and a wealth of third-party support.

Selecting the proper framework is pivotal, with factors like application complexity, UI requirements, performance demands, target platform, and your own expertise playing a crucial role. By weighing these considerations, you can confidently determine the framework that best aligns with your project’s goals and sets it on a path to success.

Make your .NET code beautiful with NDepend

Download the NDepend Trial and gain valuable insights into your .NET code within a few minutes

  • Full Stack Course
  • React Native
  • CSS Frameworks
  • JS Frameworks
  • Web Development

Difference between WPF and WinForms

WPF (Windows Presentation Foundation): WPF, as the name suggests, is a UI framework used for developing Windows or desktop client applications. It is the latest approach to the GUI framework being used with the .NET framework. It was introduced to develop Windows client apps that run on the Windows operating system, and the next generation of Windows forms. It has all the functionality that is being required to develop, run, execute, manage, and handle Windows client applications. 

It generally provides holistic means for combining or integrating UI, 2D and 3D graphics, digital media, and documents. It is responsible for developing, displaying, and manipulating UI, documents, images, etc., in Windows 7 and later operating systems. It is the current platform for developing windows applications.  

WinForms (Windows Form Application): WinForms, as the name suggests, is basically a GUI-based approach introduced to the .NET framework. Prior to WPF and Silverlight, it was the main API for .NET that is being used to build GUI. It does not require any type of support other than runtime and OS for developing a standalone application. 

One can develop apps that are easy to deploy, update, manage, and work offline while connected to the Internet. The development of WinForms is very simple as it is only based on the drag and drop placement of UI controls on canvas. It is the old platform for developing desktop applications.  

Difference between WPF and WinForms:

It is based on DirectX with XAML support.   It provides access to the native windows library of common controls.  
It uses markup language for designing UI allowing the design of complex user interfaces.   It does not use a markup language for design. In fact, it uses event-driven controls for the design. 
It can render fast as compared to WinForms, complexity, and support.   It renders slow as compared to WPF.  
It can be used to develop and design both windows applications and web applications.   It can only be used to develop and design windows applications.  
It has unlimited UI customization and controls can be customized easily as it is totally written from scratch.  In this, controls are limited and difficult to customize.  
It is easier to separate UI from back-end logic.   It is tough to separate UI from back-end logic. 
It allows you to handle large data sets because of its in-built feature “user interface virtualization”. It does not have a “user interface virtualization” feature.  
It takes up more RAM than WinForms.   It takes a smaller memory footprint. 
It is considered good when the application requires many media types, create a skinned UI, bind to XML, develop a desktop application having a web-like navigation style.   It is considered good if you want to develop an application without much added modern functionality, more online resources.  
It offers effective and fully supported data binding as compared to WinForms.   It offers data binding but in a limited way. Therefore, it’s less effective as compared to WPF. 
It also offers rich, interactive, animated, hardware accelerated, vector 2D and 3D capabilities for developing applications.   It does not offer any rich, Interactive, animated, hardware accelerated, vector 2D and 3D capabilities as compared to WPF.  
It is a little bit tough, time-consuming, and complex to use WPF as compared to WinForms.   It is simple to use WinForms as controls can be used easily, it’s less time-consuming and less tricky as compared to WPF.  
It has an inbuilt story boarding feature and animation model, it has the ability to use business objects in UI declaratively.   It does not provide such features. 

  

author

Please Login to comment...

Similar reads.

  • Difference Between
  • Web Technologies
  • Web Technologies - Difference Between
  • California Lawmakers Pass Bill to Limit AI Replicas
  • Best 10 IPTV Service Providers in Germany
  • Python 3.13 Releases | Enhanced REPL for Developers
  • IPTV Anbieter in Deutschland - Top IPTV Anbieter Abonnements
  • Content Improvement League 2024: From Good To A Great Article

Improve your Coding Skills with Practice

 alt=

What kind of Experience do you want to share?

C# Corner

  • TECHNOLOGIES
  • An Interview Question

WPF

WPF vs. WinForms

windows presentation foundation form

  • Sandeep Mishra
  • Jan 22, 2021
  • Other Artcile

In this article, you will learn about WPF vs WinForms.

Introduction

Windows forms.

WPF vs WinForms

WPF Desktop Applications

WPF vs WinForms

  • Each Window or Page has a .xaml file for adding controls and a .cs, .vb, e.t.c file which is the code-behind file more like an ASP.NET approach.

WPF vs WinForms

  • This file acts as the entry to the application.
  • <Window x:Class= "WpfApp1.MainWindow"   
  •     xmlns= "http://schemas.microsoft.com/winfx/2006/xaml/presentation"   
  •     xmlns:x= "http://schemas.microsoft.com/winfx/2006/xaml"   
  •     xmlns:d= "http://schemas.microsoft.com/expression/blend/2008"   
  •     xmlns:mc= "http://schemas.openxmlformats.org/markup-compatibility/2006"   
  •     xmlns:local= "clr-namespace:WpfApp1"   
  •    mc:Ignorable= "d"   
  •    Title= "MainWindow"  Height= "450"  Width= "800" >  
  •     <StackPanel>  
  •         <TextBox></TextBox>  
  •     </StackPanel>  
  • </Window>  
  •    Title= "MainWindow"  Height= "500"  Width= "800" >  
  •     <Button Padding= "5" >  
  •         <StackPanel Orientation= "Horizontal" >  
  •             <Image Source= "/Image.jpg"  Height= "25"  Width= "50"  />  
  •             <TextBlock Margin= "5,0" >I'm a Button</TextBlock>  
  •         </StackPanel>  
  •     </Button>  

WPF vs WinForms

  •         Title= "MainWindow"  Height= "500"  Width= "800" >  
  •     <StackPanel Margin= "10" >  
  •         <WrapPanel Margin= "0,10" >  
  •             <Label Content= "Your Text Here:"  FontWeight= "Bold" />  
  •             <TextBox Name= "txtBind"  Height= "20"  Width= "250"   RenderTransformOrigin= "-2.75,0.587"  Margin= "59,0,336,0" />  
  •         </WrapPanel>  
  •             <TextBlock Text= "Bound-Text: "  FontWeight= "Bold"  />  
  •             <TextBlock Text= "{Binding Path=Text, ElementName=txtBind}"  />  

WPF vs WinForms

  • WPF Vs WinForms

C# Corner Ebook

WPF Simplified: Build Windows Apps Using C# and XAML

Navigation Menu

Search code, repositories, users, issues, pull requests..., provide feedback.

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly.

To see all available qualifiers, see our documentation .

  • Notifications You must be signed in to change notification settings

Repository for WPF related samples

microsoft/WPF-Samples

Folders and files.

NameName
542 Commits
policies policies

Repository files navigation

Wpf-samples.

This repo contains the samples that demonstrate the API usage patterns and popular features for the Windows Presentation Foundation in the .NET for Desktop. These samples were initially hosted on MSDN , and we are gradually moving all the interesting WPF samples over to GitHub. All the samples have been retargeted to .NET 8.0 .

You can also find an archive of samples targeting .NET 4.7.2 in the netframework branch.

The samples in this repo are generally about illustrating specific concepts and may go against accessibility best practices. However, the team has spent some time illustrating accessibility best practices in a subset of these samples.

  • ExpenseItIntro
  • ExpenseItDemo
  • DataBindingDemo
  • CustomComboBox
  • EditingExaminerDemo

For WPF samples using .NET Framework, visit here .

Unless otherwise mentioned, the samples are released under the MIT license

Help us improve our samples

Help us improve out samples by sending us a pull-request or opening a GitHub Issue

Questions: mail [email protected]

WPF development

For .net 8 - main branch.

These samples require Visual Studio 2022(v17.8) to build, test, and deploy, and also require the most recent .NET 8 SDK.

Get a free copy of Visual Studio 2022 Community Edition

These samples require Visual Studio 2022(v17.7), Visual Studio 2022 for Mac (v17.6) to build, test, and deploy, and also require the .NET 7 SDK.

These samples require Visual Studio 2022(v17.2), Visual Studio 2022 for Mac (v17.6) to build, test, and deploy, and also require the .NET 6 SDK.

WPF on .NET has been open-sourced, and is now available on Github

Using the samples

To use the samples with Git, clone the WPF-Samples repository with 'git clone https://github.com/microsoft/WPF-Samples '

After cloning the WPF-Samples respository, there will be two solution files in the root directory: WPF-Samples.sln and WPF-Samples.msbuild.sln

  • To build the samples, open one of the solution files in Visual Studio 2022 and build the solution.
  • Alternatively, navigate to the directory of a sample and build with 'dotnet build' or 'msbuild' specifying the target project file.
  • WPF-Samples.msbuild.sln contains projects that can be built only with msbuild or Visual Studio, and will not compile with dotnet build . These projects contain C++ code, for which there is no support in dotnet build

The easiest way to use these samples without using Git is to download the zip file containing the current version (using the link below or by clicking the "Download ZIP" button on the repo page). You can then unzip the entire archive and use the samples in Visual Studio 2022.

Download the samples ZIP

  • Before you unzip the archive, right-click it, select Properties, and then select Unblock.
  • Most samples should work independently
  • By default, all the samples target .NET 8.0. (Installers for the .NET 8 SDK can be found at https://dotnet.microsoft.com/en-us/download )

For more info about the programming models, platforms, languages, and APIs demonstrated in these samples, please refer to the guidance available in MSDN . These samples are provided as-is in order to indicate or demonstrate the functionality of the programming models and feature APIs for WPF.

Code of conduct

Security policy, releases 55, contributors 62.

  • PowerShell 0.6%
  • JavaScript 0.2%
  • Visual Basic .NET 0.0%
  • Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers
  • Advertising & Talent Reach devs & technologists worldwide about your product, service or employer brand
  • OverflowAI GenAI features for Teams
  • OverflowAPI Train & fine-tune LLMs
  • Labs The future of collective knowledge sharing
  • About the company Visit the blog

Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Get early access and see previews of new features.

Learning Windows Forms vs. Windows Presentation Foundation

So I've been thinking of going for Microsoft certification and I have to make a choice (for now) between Windows Forms and WPF for developing Windows applications. I have had good exposure to Windows Forms but never tried WPF before. Furthermore, most of the job postings where I live seem to be WinForms-oriented. That might change in the next few years, so I was wondering if I should get started on learning WPF or stick to the tried and true Forms.

Any insight?

Firas Assaad's user avatar

4 Answers 4

  • Although most current dev.positions will focus on WinForms (or ASP.NET for that matter), WPF is starting to get accepted as a 'serious' platform. With serious I mean that people are starting to think about using it for LOB-applications. With the release of Prism it's clear that Microsoft is starting to promote WPF in other ways than just the 'eye-candy' features. This means WPF is going to be presented as a WinForms alternative pretty soon.
  • Learning WPF will mean you'll also learn Silverlight at the same time. So you have two modern technologies at your disposal. [Added] -WPF has more to offer than just the eye-candy and you can benefit from it a lot without being a creative genius. The API is intuitive (and fun) and can offer a lot of improved productivity.

In short, I'd say if you want to be 'future-proof' learn WPF.

Ruben Steins's user avatar

In "enterprise" programming, I don't see an immediate need for WPF development. The reasons for this:

  • Companies are not running on the newest hardware, and tend to migrate to remote desktops (RDP/Citrix).
  • A developer can design a decent interface using Windows.Forms controls. In WPF, you need a designer. In large companies there are designers, in most companies I know, the IT department is staffed with programmers and system-engineers, no designers.

Software for the "home market" is another story.

GvS's user avatar

  • I woulda thought this q would get more upvotes :( Can everyone kinda just butt in here and upvote this answer until it says 13 upvotes? That would be kinda cool :) –  βӔḺṪẶⱫŌŔ Commented May 15, 2011 at 11:31

If you want to go the certification route to learn then WPF is a good choice. It will take a few years before it will really take over from winforms but It's a safe bet it will so it's a good investment to learn.

If you're more of a self learner and just want to get certified to improve your chances on the job market then I'd go with winforms for the certification. You can pick up WPF when you need it. By the time you really need to have a WPF certification it will probably be easier for you because you've already used it.

Mendelt's user avatar

WPF leverages XAML for the design/visual experience this is the same technology that Silverlight uses and in the future will be leveraged heavily by other aspects of .NET 4.0, specifically, WCF (web services) and WF (workflow).

I would highly recommend learning it if you have the cycles, however for certification purposes it might be easier to just go ahead and do the WinForms exam as WPF is quite different and in my experience had a bit of a learning curve (because of how different it is from WinForms).

Eric Schoonover's user avatar

Your Answer

Reminder: Answers generated by artificial intelligence tools are not allowed on Stack Overflow. Learn more

Sign up or log in

Post as a guest.

Required, but never shown

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy .

Not the answer you're looking for? Browse other questions tagged c# .net wpf winforms or ask your own question .

  • The Overflow Blog
  • Mobile Observability: monitoring performance through cracked screens, old...
  • Featured on Meta
  • Announcing a change to the data-dump process
  • Bringing clarity to status tag usage on meta sites
  • What does a new user need in a homepage experience on Stack Overflow?
  • Feedback requested: How do you use tag hover descriptions for curating and do...
  • Staging Ground Reviewer Motivation

Hot Network Questions

  • In 1982 Admiral Grace Hopper said "I still haven't found out why helicopter rotors go the way they do". If she were here today, how might one answer?
  • What is this device in my ceiling making out of battery chirps?
  • decode the pipe
  • A SF novel where one character makes a "light portrait" of another one, with huge consequences
  • How do I backup only changed files on an external hard drive?
  • Reference request: locally erasable delta-functor is universal
  • A classic problem about matrix
  • Would it be Balanced to Give Everyone Warlock Slots for Casting Racial Spells?
  • Is it illegal to use a fake state ID to enter a private establishment even when a legitimate ID would've been fine?
  • Did Gandalf know he was a Maia?
  • Is it fine to call a 26 year old character a young adult?
  • Disable terminal switch focus shortcut (Cmd+Left/Right Arrow)
  • Can it be acceptable to take over CTRL + F shortcut in web app
  • Functor composition rule necessary?
  • What happens to entropy during compression?
  • I have two identical LaTeX files, with different file names. Only one yields "undefined references." Why is this happening?
  • All four children have England birth index page changes
  • Expensive constructors. Should they exist? Should they be replaced?
  • Bash script that takes multiple path arguments and checks if files can be successfully created there
  • If you have two probabilities, how do you describe how much more likely one is than the other?
  • How to setup a home lab with a custom domain name?
  • How can I align this figure with the page numbering?
  • Why is the wiper fluid hose on the Mk7 Golf covered in cloth tape?
  • How do I configure LXQt to show text the same size as Firefox and other applications?

windows presentation foundation form

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Tutorial: Create a simple WPF application with C#

  • 13 contributors

By completing this tutorial, you become familiar with many of the tools, dialog boxes, and designers that you can use when you develop applications with Visual Studio. You create a "Hello, World" application, design the UI, add code, and debug errors, while you learn about working in the integrated development environment ( IDE ).

Prerequisites

  • If you haven't already installed Visual Studio, go to the Visual Studio downloads page to install it for free.
  • Make sure the .NET desktop development workload is installed. You can verify this configuration in the Visual Studio Installer.
  • You can use either .NET Framework or .NET Core for this tutorial. .NET Core is the newer, more modern framework. .NET Core requires Visual Studio 2019 version 16.3 or later.

What is WPF?

WPF, or Windows Presentation Foundation, is a UI (user interface) 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.

WPF is part of .NET, so if you have previously built applications with .NET using ASP.NET or Windows Forms, the programming experience should be familiar. WPF uses the Extensible Application Markup Language XAML to provide a declarative model for application programming. For more information, see WPF .NET overview .

Configure the IDE

When you launch Visual Studio, the start window opens first. Select Continue without code to open the development environment. You see tool windows, the menus and toolbars, and the main window space. Tool windows are docked on the left and right sides of the application window. The search box, menu bar, and the standard toolbar are located at the top. When you load a solution or project, editors and designers appear in the central space of the application window. When you develop an application, you spend most of your time in this central area.

Create the project

When you create an application in Visual Studio, you first create a project and a solution. For this example, you create a Windows Presentation Foundation (WPF) project.

Open Visual Studio.

On the start window, choose Create new project .

View the 'Create a new project' window

On the Create a new project screen, search for "WPF," choose WPF Application , and then choose Next .

Screenshot of the 'Create a new project' dialog with 'WPF' entered in the search box, and the 'WPF Application' project template highlighted.

At the next screen, give the project a name, HelloWPFApp , and choose Next .

Screenshot of the 'Configure your new project' dialog in Visual Studio with 'HelloWPFApp' entered in the Project name field.

In the Additional information window, .NET Core 3.1 should already be selected for your target framework. If not, select .NET Core 3.1 . Then, choose Create .

Screenshot that shows the Additional information window in Visual Studio with .NET Core 3.1 selected as the target framework for the new project.

Visual Studio creates the HelloWPFApp project and solution, and Solution Explorer shows the various files. The WPF Designer shows a design view and a XAML view of MainWindow.xaml in a split view. You can slide the splitter to show more or less of either view. You can choose to see only the visual view or only the XAML view.

WPF project and solution in the IDE

For more information about XAML (eXtensible Application Markup Language), see the XAML overview for WPF page.

After you create the project, you can customize it. To do so, choose Properties Window from the View menu, or press F4 . Then, you can display and change options for project items, controls, and other items in an application.

Properties window

On the start window, choose Create a new project .

Screenshot of the start window in Visual Studio 2022 with the 'Create a new project' option highlighted.

In the Additional information window, verify that .NET 8.0 is selected for your target framework. Then, choose Create .

Screenshot that shows the Additional information window in Visual Studio with .NET 8.0 selected as the target framework for the new project.

Design the user interface (UI)

If the designer isn't open, select MainWindow.xaml and press Shift + F7 to open the designer.

We add three types of controls to this application: a TextBlock control, two RadioButton controls, and a Button control.

Add a TextBlock control

Press Ctrl + Q to activate the search box and type Toolbox . Choose View > Toolbox from the results list.

In the Toolbox , expand the Common WPF Controls node to see the TextBlock control.

Toolbox with the TextBlock control highlighted

Add a TextBlock control to the design surface by choosing the TextBlock item and dragging it to the window on the design surface. Center the control near the top of the window. In Visual Studio 2019 and later, you can use the red guidelines to center the control.

Your window should resemble the following illustration:

TextBlock control on the MainWindow form

The XAML markup should look something like the following example:

Screenshot of the Toolbox window with the TextBlock control selected in the list of Common WPF Controls.

Add a TextBlock control to the design surface by choosing the TextBlock item and dragging it to the window on the design surface. Center the control near the top of the window. You can use the guidelines to center the control.

Your window should resemble the following image:

Screenshot of the TextBlock control on the design surface. Guidelines are shown for positioning and resizing the control.

Customize the text in the text block

In the XAML view, locate the markup for TextBlock and change the Text attribute from TextBox to Select a message option and then choose the Display button.

Center the TextBlock again if you like, and then save your changes by pressing Ctrl+S or using the File menu item.

Next, you add two RadioButton controls to the form.

Add radio buttons

In the Toolbox , find the RadioButton control.

Toolbox window with RadioButton control selected

Add two RadioButton controls to the design surface by choosing the RadioButton item and dragging it to the window on the design surface. Move the buttons (by selecting them and using the arrow keys) so that the buttons appear side by side under the TextBlock control. Use the red guidelines to align the controls.

Your window should look like this:

MainWindow form with TextBlock and two radio buttons

In the Properties window for the left RadioButton control, change the Name property (the property at the top of the Properties window) to HelloButton .

RadioButton properties window

In the Properties window for the right RadioButton control, change the Name property to GoodbyeButton , and then save your changes.

Next, you add display text for each RadioButton control. The following procedure updates the Content property for a RadioButton control.

Screenshot of the Toolbox window with the RadioButton control selected in the list of Common WPF Controls.

Add two RadioButton controls to the design surface by choosing the RadioButton item and dragging it to the window on the design surface. Move the buttons (by selecting them and using the arrow keys) so that the buttons appear side by side under the TextBlock control. You can use the guidelines to align the controls.

Screenshot of the Design window for Greetings.xaml, showing a TextBlock control and two RadioButton controls positioned on the design surface.

Add display text for each radio button

Update the Content attribute for the two radio buttons HelloButton and GoodbyeButton to "Hello" and "Goodbye" in the XAML. The XAML markup should now look similar to the following example:

Set a radio button to be checked by default

In this step, we set HelloButton to be checked by default so that one of the two radio buttons is always selected.

In the XAML view, locate the markup for HelloButton.

Add an IsChecked attribute and set it to True . Specifically, add IsChecked="True" .

The XAML markup should now look similar to the following example:

The final UI element that you add is a Button control.

Add the button control

In the Toolbox , find the Button control, and then add it to the design surface under the RadioButton controls by dragging it to the form in the design view. If you're using Visual Studio 2019 or later, a red line helps you center the control.

In the XAML view, change the value of Content for the Button control from Content="Button" to Content="Display" , and then save the changes.

Your window should resemble the following illustration.

MainWindow form with control labels

In the Toolbox , find the Button control, and then add it to the design surface under the RadioButton controls by dragging it to the form in the design view. The guidelines can help you center the control.

Your window should resemble the following screenshot.

Screenshot of the Design window for Greetings.xaml showing a TextBlock control, two RadioButton controls labeled 'Hello' and 'Goodbye', and a button labeled 'Display'.

Add code to the display button

When this application runs, a message box appears after a user chooses a radio button and then chooses the Display button. One message box appears for Hello, and another appears for Goodbye. To create this behavior, you add code to the Button_Click event in MainWindow.xaml.cs .

On the design surface, double-click the Display button.

MainWindow.xaml.cs opens, with the cursor in the Button_Click event.

Enter the following code:

Save the application.

When you double-click the Display button, Click="Button_Click" is added to the XAML.

Debug and test the application

Next, you debug the application to look for errors and test that both message boxes appear correctly. The following instructions tell you how to build and launch the debugger, but later you might read Build a WPF application (WPF) and Debug WPF for more information.

Change the name of MainWindow.xaml

Let's give MainWindow a more specific name. In Solution Explorer , right-click on MainWindow.xaml and choose Rename . Rename the file to Greetings.xaml .

Find and fix errors

In this step, you find the error that we caused earlier by changing the name of the MainWindow.xaml file.

Start debugging and find the error

Start the debugger by pressing F5 or selecting Debug , then Start Debugging .

A Break Mode window appears, and the Output window indicates that an IOException has occurred: Cannot locate resource mainwindow.xaml .

IOException message

Stop the debugger by choosing Debug > Stop Debugging .

We renamed MainWindow.xaml to Greetings.xaml , but the code still refers to MainWindow.xaml as the startup URI for the application, so the project can't start.

Screenshot of the Output window showing a System.IO.IOException with the message, Cannot locate resource mainwindow.xaml.

We renamed MainWindow.xaml to Greetings.xaml at the start of this tutorial, but the code still refers to MainWindow.xaml as the startup URI for the application, so the project can't start.

Specify Greetings.xaml as the startup URI

In Solution Explorer , open the App.xaml file.

Change StartupUri="MainWindow.xaml" to StartupUri="Greetings.xaml" , and save the changes.

As an optional step, it avoids confusion to change the title of your application window to match this new name.

In Solution Explorer , open the Greetings.xaml file that you just renamed.

Change the value of the Window.Title property from Title="MainWindow" to Title="Greetings" , and save the changes.

Start the debugger again (press F5 ). You should now see the Greetings window of your application.

Screenshot of running app

Now close the application window to stop debugging.

Debug with breakpoints

You can test the code during debugging by adding some breakpoints. You can add breakpoints by choosing Debug > Toggle Breakpoint , by clicking in the left margin of the editor next to the line of code where you want the break to occur, or by pressing F9 .

Add breakpoints

Open Greetings.xaml.cs , and select the following line: MessageBox.Show("Hello.")

Add a breakpoint from the menu by selecting Debug , then Toggle Breakpoint .

A red circle appears next to the line of code in the far left margin of the editor window.

Select the following line: MessageBox.Show("Goodbye.") .

Press the F9 key to add a breakpoint, and then press F5 to start debugging.

In the Greetings window, choose the Hello radio button, and then choose the Display button.

The line MessageBox.Show("Hello.") is highlighted in yellow. At the bottom of the IDE, the Autos, Locals, and Watch windows are docked together on the left side, and the Call Stack, Breakpoints, Exception Settings, Command, Immediate, and Output windows are docked together on the right side.

Breakpoint in the debugger

On the menu bar, choose Debug > Step Out .

The application resumes execution, and a message box with the word "Hello" appears.

Choose the OK button on the message box to close it.

In the Greetings window, choose the Goodbye radio button, and then choose the Display button.

The line MessageBox.Show("Goodbye.") is highlighted in yellow.

Choose the F5 key to continue debugging. When the message box appears, choose the OK button on the message box to close it.

Close the application window to stop debugging.

On the menu bar, choose Debug > Disable All Breakpoints .

Screenshot of a debug session in Visual Studio. The code window for Greetings.xaml.cs shows execution stopped at a breakpoint with a line highlighted in yellow.

View a representation of the UI elements

In the running app, you should see a widget that appears at the top of your window. The widget is a runtime helper that provides quick access to some helpful debugging features. Select the first button, Go to Live Visual Tree . You should see a window with a tree that contains all the visual elements of your page. Expand the nodes to find the buttons you added.

Screenshot of Live Visual Tree window

Build a release version of the application

Now that you've verified that everything works, you can prepare a release build of the application.

On the main menu, select Build > Clean solution to delete intermediate files and output files that were created during previous builds. This step isn't required, but it cleans up the debug build outputs.

Change the build configuration for HelloWPFApp from Debug to Release by using the dropdown control on the toolbar (it says "Debug" currently).

Build the solution by choosing Build > Build Solution .

Congratulations on completing this tutorial! You can find the .exe you built under your solution and project directory ( ...\HelloWPFApp\HelloWPFApp\bin\Release ).

Congratulations on completing this tutorial! To learn even more, continue with the following tutorials.

Continue with more WPF tutorials

  • Productivity tips

Was this page helpful?

Additional resources

  • ASP.NET MVC
  • ASP.NET WebForms

What is WPF?

WPF, which stands for Windows Presentation Foundation, is Microsoft's latest approach to a GUI framework, used with the .NET framework.

But what IS a GUI framework? GUI stands for Graphical User Interface, and you're probably looking at one right now. Windows has a GUI for working with your computer, and the browser that you're likely reading this document in has a GUI that allows you to surf the web.

A GUI framework allows you to create an application with a wide range of GUI elements, like labels, textboxes and other well known elements. Without a GUI framework you would have to draw these elements manually and handle all of the user interaction scenarios like text and mouse input. This is a LOT of work, so instead, most developers will use a GUI framework which will do all the basic work and allow the developers to focus on making great applications.

There are a lot of GUI frameworks out there, but for .NET developers, the most interesting ones are currently WinForms and WPF. WPF is the newest, but Microsoft is still maintaining and supporting WinForms. As you will see in the next chapter, there are quite a few differences between the two frameworks, but their purpose is the same: To make it easy to create applications with a great GUI.

In the next chapter, we will look at the differences between WinForms and WPF.

  • Norwegian Bokmål

WPF Tutorial

  • WPF Tutorial

WPF - Overview

  • WPF - Environment Setup
  • WPF - Hello World
  • WPF - XAML Overview
  • WPF - Elements Tree
  • WPF - Dependency Properties
  • WPF - Routed Events
  • WPF - Controls
  • WPF - Layouts
  • WPF - Nesting Of Layout
  • WPF - Input
  • WPF - Command Line
  • WPF - Data Binding
  • WPF - Resources
  • WPF - Templates
  • WPF - Styles
  • WPF - Triggers
  • WPF - Debugging
  • WPF - Custom Controls
  • WPF - Exception Handling
  • WPF - Localization
  • WPF - Interaction
  • WPF - 2D Graphics
  • WPF - 3D Graphics
  • WPF - Multimedia
  • WPF Useful Resources
  • WPF - Quick Guide
  • WPF - Useful Resources
  • WPF - Discussion
  • Selected Reading
  • UPSC IAS Exams Notes
  • Developer's Best Practices
  • Questions and Answers
  • Effective Resume Writing
  • HR Interview Questions
  • Computer Glossary

WPF stands for Windows Presentation Foundation. It is a powerful framework for building Windows applications. This tutorial explains the features that you need to understand to build WPF applications and how it brings a fundamental change in Windows applications.

WPF was first introduces in .NET framework 3.0 version, and then so many other features were added in the subsequent .NET framework versions.

WPF Architecture

Before WPF, the other user interface frameworks offered by Microsoft such as MFC and Windows forms, were just wrappers around User32 and GDI32 DLLs, but WPF makes only minimal use of User32. So,

  • WPF is more than just a wrapper.
  • It is a part of the .NET framework.
  • It contains a mixture of managed and unmanaged code.

The major components of WPF architecture are as shown in the figure below. The most important code part of WPF are −

  • Presentation Framework
  • Presentation Core

WPF Architecture

The presentation framework and the presentation core have been written in managed code. Milcore is a part of unmanaged code which allows tight integration with DirectX (responsible for display and rendering). CLR makes the development process more productive by offering many features such as memory management, error handling, etc.

WPF – Advantages

In the earlier GUI frameworks, there was no real separation between how an application looks like and how it behaved. Both GUI and behavior was created in the same language, e.g. C# or VB.Net which would require more effort from the developer to implement both UI and behavior associated with it.

In WPF, UI elements are designed in XAML while behaviors can be implemented in procedural languages such C# and VB.Net. So it very easy to separate behavior from the designer code.

With XAML, the programmers can work in parallel with the designers. The separation between a GUI and its behavior can allow us to easily change the look of a control by using styles and templates.

WPF – Features

WPF is a powerful framework to create Windows application. It supports many great features, some of which have been listed below −

Feature Description
Control inside a Control Allows to define a control inside another control as a content.
Data binding Mechanism to display and interact with data between UI elements and data object on user interface.
Media services Provides an integrated system for building user interfaces with common media elements like images, audio, and video.
Templates In WPF you can define the look of an element directly with a Template
Animations Building interactivity and movement on user Interface
Alternative input Supports multi-touch input on Windows 7 and above.
Direct3D Allows to display more complex graphics and custom themes

IMAGES

  1. An Overview of Windows Presentation Foundation

    windows presentation foundation form

  2. An Introduction To Windows Presentation Foundation Wpf Architecture Images

    windows presentation foundation form

  3. An Overview of Windows Presentation Foundation

    windows presentation foundation form

  4. 6460a Visual Studio 2008 Windows Presentation Foundation Form

    windows presentation foundation form

  5. Windows Presentation Foundation. El final de Windows Forms…

    windows presentation foundation form

  6. Что такое Windows Presentation Foundation

    windows presentation foundation form

VIDEO

  1. Windows Presentation Foundation (WPF) Grid Layout Control Part 2

  2. How to create a Windows Forms application in Visual Studio

  3. Windows Presentation Foundation الدرس الأول

  4. WPF in action

  5. WPF

  6. WPF Development with Oxygene for .NET

COMMENTS

  1. What is Windows Presentation Foundation

    Welcome to the Desktop Guide for Windows Presentation Foundation (WPF), a UI framework that is resolution-independent and uses a vector-based rendering engine, built to take advantage of modern graphics hardware. WPF provides a comprehensive set of application-development features that include Extensible Application Markup Language (XAML ...

  2. Tutorial: Use Windows Presentation Foundation (WPF)

    On the start window, choose Create a new project. On the Create a new project window, search for "WPF" and select Visual Basic in the All languages drop-down list. Choose WPF App (.NET Framework), and then choose Next. Give the project a name, HelloWPFApp, and select Create. Visual Studio creates the HelloWPFApp project and solution.

  3. Windows Presentation Foundation

    Rich, productive, extensible. Windows Presentation Foundation (WPF) and XAML combine into a rich presentation system for building Windows desktop applications with visually stunning user experiences that incorporate UI, media, and complex business models. Rapidly develop enterprise-class line of business applications with a comprehensive set of ...

  4. Desktop Guide for WPF and Windows Forms on .NET

    Welcome to the Desktop Guide. The Desktop Guide is a set of documentation for .NET-based Windows UI technologies including Windows Presentation Foundation (WPF) and Windows Forms (WinForms). The Desktop Guide will cover both .NET 5 (and .NET Core 3.1) and later versions, along with .NET Framework.

  5. Windows Presentation Foundation

    Windows Presentation Foundation (WPF) is a free and open-source user interface framework for Windows-based desktop applications. WPF applications are based in .NET, ... Windows Forms features are possible through the use of the ElementHost and WindowsFormsHost classes.

  6. What is the difference between Window Presentation Foundation and WCF

    WPF == Windows Presentation Foundation WCF == Windows Communication Foundation. WPF is the direct replacement for WinForms. WCF is a framework for talking to webservices, it replaces Remoting. I could waffle for hours on this, but that is a short answer for you :)

  7. Windows Presentation Foundation (WPF)

    Windows Presentation Foundation (WPF) is a UI framework for building Windows desktop applications. WPF supports a broad set of application development features, including an application model, resources, controls, graphics, layout, data binding and documents. WPF uses the Extensible Application Markup Language (XAML) to provide a declarative ...

  8. Windows Presentation Foundation (WPF)

    Windows Presentation Foundation (WPF) is a UI framework for building Windows desktop applications. WPF supports a broad set of application development features, including an application model, resources, controls, graphics, layout, data binding and documents. WPF uses the Extensible Application Markup Language (XAML) to provide a declarative model for application programming.

  9. WPF vs WinForms

    April 24, 2024 7 minutes read . If you're a developer faced with the decision of selecting between Windows Presentation Foundation (WPF) and Windows Forms (WinForms) commonly referred to as WPF vs WinForms, you may be eager to understand the distinctions between these two UI frameworks.In this comprehensive guide, we will offer an in-depth comparison of WPF and WinForms.

  10. Welcome

    Welcome to this WPF tutorial, currently consisting of 126 articles, where you'll learn to make your own applications using the WPF UI framework. If you're brand new to WPF, then we recommend that you start from the first chapter and then read your way through all of it. Have a look at the Table of contents to the right, where all the chapters ...

  11. Windows Presentation Foundation for .NET 8 documentation

    Learn about using Windows Presentation Foundation (WPF), an open-source, graphical user interface for Windows, on .NET.

  12. Difference between WPF and WinForms

    WPF (Windows Presentation Foundation): WPF, as the name suggests, is a UI framework used for developing Windows or desktop client applications. It is the latest approach to the GUI framework being used with the .NET framework. It was introduced to develop Windows client apps that run on the Windows operating system, and the next generation of Windows forms.

  13. WPF vs. WinForms

    The abbreviation W.P.F simply refers to Microsoft's Windows Presentation Foundation, and WinForms is a simple concatenation of Windows Forms Applications. These are both Microsoft's Windows Applications Graphical User Interfaces that developers may use to develop Windows desktop applications. This article focuses on describing the major ...

  14. Windows Presentation Foundation (WPF) Application Development

    Windows Presentation Foundation (WPF) and XAML combine into a rich presentation system for building Windows desktop applications with visually stunning user ...

  15. WPF Tutorial

    WPF Tutorial. WPF stands for Windows Presentation Foundation. It is a powerful framework for building Windows applications. This tutorial explains the features that you need to understand to build WPF applications and how it brings a fundamental change in Windows applications.

  16. Getting Started

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

  17. microsoft/WPF-Samples: Repository for WPF related samples

    This repo contains the samples that demonstrate the API usage patterns and popular features for the Windows Presentation Foundation in the .NET for Desktop. These samples were initially hosted on MSDN, and we are gradually moving all the interesting WPF samples over to GitHub. All the samples have been retargeted to .NET 8.0.

  18. Learning Windows Forms vs. Windows Presentation Foundation

    Learning WPF will mean you'll also learn Silverlight at the same time. So you have two modern technologies at your disposal. [Added] -WPF has more to offer than just the eye-candy and you can benefit from it a lot without being a creative genius. The API is intuitive (and fun) and can offer a lot of improved productivity.

  19. Create a new app with Visual Studio tutorial

    In this article. In this short tutorial, you'll learn how to create a new Windows Presentation Foundation (WPF) app with Visual Studio. Once the initial app has been generated, you'll learn how to add controls and how to handle events. By the end of this tutorial, you'll have a simple app that adds names to a list box.

  20. Hello World app with WPF in C#

    Open Visual Studio. On the start window, choose Create a new project.. On the Create a new project screen, search for "WPF," choose WPF Application, and then choose Next.. At the next screen, give the project a name, HelloWPFApp, and choose Next. In the Additional information window, verify that .NET 8.0 is selected for your target framework. Then, choose Create.

  21. What is WPF?

    What is WPF? WPF, which stands for Windows Presentation Foundation, is Microsoft's latest approach to a GUI framework, used with the .NET framework. But what IS a GUI framework? GUI stands for Graphical User Interface, and you're probably looking at one right now. Windows has a GUI for working with your computer, and the browser that you're ...

  22. WPF

    WPF stands for Windows Presentation Foundation. It is a powerful framework for building Windows applications. ... Before WPF, the other user interface frameworks offered by Microsoft such as MFC and Windows forms, were just wrappers around User32 and GDI32 DLLs, but WPF makes only minimal use of User32. So, WPF is more than just a wrapper.