Windows Presentation Foundation (WPF) is a powerful tool for creating Windows desktop applications. This tutorial provides an overview of WPF, looks at its DirectX underpinnings.
- [Instructor] Windows Presentation Foundation was conceived as a fresh rethinking of the graphic layer and UI composition engine for a new version of Windows. That version was called Longhorn and it suffered many setbacks. Eventually, that operating system became Windows Vista. While many parts of Longhorn were abandoned, Windows Presentation Foundation survived and it was released as part of Vista. It's usually shortened to the WPF acronym. That's what I call it most days. At its most fundamental, WPF is a set of tools, classes and APIs for creating Windows desktop applications.
Since it was designed to be the new way to build Windows applications and render graphics to the screen, it's not surprising to see that it contains a lot of usable UI parts. For instance, you can break your application into multiple windows. You can also use a subset of windows called controls where you can create a custom control and then put some of your UI into the control and then reuse it throughout the application or throughout other projects that you're working on. In the control world, there's also a set of predefind or prebuilt controls that are provided by Microsoft.
These are the standard UI elements you work with like buttons and text blocks, list box and combo boxes, layout engines and this is also where you find things like sliders and scroll bars. You can also break your application into another subset called pages. This uses a web metaphor. You create pages, you put them inside a frame and then WPF provides a navigation framework where you can move forward and backwards to these list of pages. Very similar to what happens in a browser. There's also a set of what I call UI renderers.
These are special classes that are optimized for rendering very complex UIs so these are things like shader effects. There's also a 3D engine built in to WPF. WPF contains interesting approaches to solving UI problems and it uses new practices for code construction and markup languages. For instance, Microsoft created this new XML markup called XAML that is used to define your UI. That gives you separations of concerns. Now, you can put some of your UI in the XAML file and then you can put the interaction code in a CCR code-behind file.
There's a great data binding engine built in to WPF that allows you to define data sources and data targets and then have the data binding engine move the information between the two. There's also some borrowing coming from the web world where in the web world, a lot of times you can have what's called an event bubbling where you can have an event fire on a child element and yet have it bubble up the stack and catch it on a parent element. Well, that's one of the things they've done in WPF. It's called Router Defense and this allows you to put an element inside a parent element and instead of writing the event handler on the child element, you can write it at the parent level.
There's a nice animation engine. Makes it simple for you to do really nice and complex animations. This is important when you're doing change of state in an application. There's also this idea of replaceable templates for UI components so you create a button and then you can create a template and define a different or alternate UI for the button and then tell WPF to use your alternate template whenever it renders the button. WPF supports a centralized styling. You can define the appearance and property values for one of your elements in a style and then you can apply that style across a large subset of those elements.
WPF natively supports paginated documents. On the programming side, WPF is a managed framework. It's based on the popular .NET framework. That means there are a lot of developers who know .NET. They can switch easily to WPF. You can program WPF in Visual Basic or C#. One of the most important changes is in the rendering engine. All the UI elements like buttons and list boxes are vector-based, not rasters or bitmapped. This means that the UI is more scalable at different resolutions and zoom levels.
Windows contains an imaging component. WPF has low level access to this layer therefore working with and processing digital images and image metadata is simpler than previous UI implementations. Finally and very important, WPF uses DirectX for its rendering engine. This is great news. Windows Forms, WPF's predecessor, used the GDI rendering pipeline which is old and not suitable for modern UI. According to statistics I hear from Microsoft, there are more than one million WPF developers creating applications around the world and the variety of applications is very broad.
I've seen a line of business applications in the insurance business and in financial and baking companies. I've seen interesting systems created in WPF used in the gas and oil industry and also in the mining sector. The automotive manufactures have a portfolio of apps especially in the design parts of the business. In medicine, I've seen apps for visualizing medical scans and other digital information then there are the more mundane medical applications for managing the business side of the medical clinic. And in retail, WPF applications are everywhere.
I personally worked on several inventory systems written in WPF. The takeaway for you is that WPF is used in every sector of the business world. It is a sensible choice for your company applications too. Be sure and look at the last chapter in this course. I show a few sample applications built in WPF.
- Why choose Windows Presentation Foundation?
- Exploring the project types
- Creating a WPF project in Visual Studio
- Exploring assemblies and parts
- Using the XAML editor
- Creating the UI, including tabs, details, and controls
- Using data binding
- Adding styles
- Writing interaction code
- Using control templates, 3D parts, and effects