C# WPF Introduction


This entry is part 1 of 18 in the series C# WPF

WPF stands for Windows Presentation Foundation. WPF is a graphical subsystem by Microsoft for rendering user interfaces in Windows-based applications. WPF separates the user interface from business logic. WPF employs XAML (“zammel”), an XML-based language, to define and link various interface elements. XAML, which is an acronym for Extensible Application Markup Language, is a declarative markup language available in the .NET Framework designed to simplify the UI creation. WPF applications can be deployed as standalone desktop programs or hosted as an embedded object in a website.

The post C# Introduction lists all of the C# series of posts we have at this site.

WPF Controls

We have a series of posts on WPF Controls.

Are you interested in a WPF tutorial? We have several posts here at this site, but over at WPF Tutorial they have even more. They want you through step by step. Over on the right side they have grouped all of the WPF topics.

Hello World

There is a small series of posts, separate from the listing you see on the right, on creating a WPF Hello World program. This is a good place to start if you are new to WFP.

Windows Presentation Foundation (WPF) is a technology provided by Microsoft for creating graphical user interfaces (GUI). Windows Forms was the previous technology, although both are available today. The Windows Designer of Visual Studio is at the heart of creating Windows programs. You drag and drop controls form a Toolbox to your window. With WPF, the user interface is written in a language called Extensible Application Markup Language (XAML, pronounced zammel). Most likely you are likely to combine dragging and dropping with writing zammel code.

XAML is a language that uses XML syntax and enables controls to be added to a user interface in a declarative, hierarchical way. You use XAML to describe the interface and you put your C# code in separate files which are linked to the XAML files. WPF is designed to run on PCs running Windows Vista and Windows 2008 Server, and it can be run on Windows XP and Windows Server 2003 if they have .NET 3.0 or later installed.

A style is a named set of property settings, much like Cascading Style Sheets styles in HTML or like paragraph styles in Microsoft Word. When you apply a style to an element, it sets that element’s properties to the values set in the style. This makes it easy to get a consistent look and feel among the elements of a program.

A template is similar to a style. A control template determines how a control is displayed. The look of standard Windows controls is built into the operating system, and previous frameworks used thin wrappers over the operating system’s API to display the controls. If, however, you wanted a control to have a different look, you had to write a custom control, which involved a lot of work.

In WPF, however, the “look” of a control is not built into the operating system but is just a template that you can change. So if you don’t like the look of a control with the default template, you can easily change it. With Xamarin you can use their templates to create applications for the three types of phones: iPhone, Android and Windows. The interfaces will all have the same functionality by using the same C# code-behind but will look familiar to users of these devices.

High end graphics programs, such as games, make use of a set of APIs called DirectX. It includes APIs for graphics, audio, and input. The one for producing 2D and 3D graphics, called Direct3D, is the one were interested in. Direct3D maps its API onto the low-level hardware instructions of the graphics card. This allows programs to take advantage of hardware acceleration, making them much faster, but it is difficult to program in so non-gaming applications will rarely use it.

Windows Forms programs render their objects using User32 and the GDI, which is inefficient and since the rendering is done within the operating system it does not take advantage of the powerful graphics cards out today. Additionally, you can’t easily customize the look and feel of the interface and their controls (buttons, text boxes and so on) without build custom controls.

Under WPF, the path from the processor to the screen is entirely different from in Windows Forms. The new engine sends all rendering to Direct3D. Even simple text gets the full power of the graphics card’s capability. And it’s all done without any extra work required by the programmer.

Regarding text, WPF is responsive. When the size of the screen changes, the text flows and changes accordingly. Another benefit of flow documents is that it supports multiple columns and pagination. WPF has built-in support for vector-graphic 2D and 3D shapes. Shapes can be filled with solid colors, gradients, images, or even video. Shapes can behave like controls, including such things as hit testing and keyboard and mouse input.

Series NavigationC# WPF First Program >>