WPF is short for Windows Presentation Foundation. Microsoft takes it as a next-generation presentation system for building Windows client applications with visually stunning user experiences. Obviously, the “next” is compared with MFC; a presentation system for windows before WPF. WPF brings in many new features for developers.
1) DirectX instead of GDI/GDI+/user32
To achieve a visually stunning UI efficiently, WPF uses DirectX as its graphic engine instead of GDI/GDI+/User32. The difference between them is that DirectX has hardware acceleration while GDI/GDI+/User32 does not. That means that DirectX can use the GPU to do part of the rendering work while GDI/GDI+/User32 can only use the CPU to complete entire rendering work. When dealing with complex textures, special effects such as partial transparency, anti-aliasing, and three-dimensional graphics, a GPU is much faster than a CPU. Indeed, DirectX is designed as a game developer’s toolkit and is supported by all the modern video cards, so a WPF application can easily implement excellent graphics effects similar to those used in games. But in some cases, such as when the DirectX version level is lower than 9, a WPF application doesn’t have hardware acceleration. Open the site http://msdn.microsoft.com/en-US/eng/library/ms742196(v=vs.110).aspx for all the cases.
In old presentation systems such as MFC, data is used by the UI. When a datum is modified, the UI doesn’t update until a refresh function is called. On the contrary, WPF is a data-driven system. The change of a datum would cause the UI to refresh automatically if the datum is a Dependency Property and AffectsArrange is true. Also, the change of UI would cause the change of data automatically if there is a two-way binding between them.
3) Resolution Independence
Traditional windows applications are bound by certain assumptions about resolution. Developers usually assume a standard monitor resolution (such as 1366 x 768 pixels), and design the window in mind and try to ensure reasonable resizing behavior for smaller and larger dimensions. The problem is that the application isn’t scalable. As a result, when the application runs on a monitor with higher resolution, the application window will be smaller and more difficult to read. While with lower resolution, the window for the application will be larger and therefore part of the windows will be displayed off-screen .
WPF uses device-independent units to measure Windows and other elements, it bases its scaling on the system DPI setting. A unit is defined as 1/96 of an inch. The physical size (the real size when it’s displayed on the monitor) of a unit is calculated as
[Physical Unit Size] = [Device-Independent Unit Size] x [System DPI]
= 1/96 x System DPI (pixels)
= 1/96 x System DPI / Screen DPI (inch)
According to the definition of the unit and calculation of physical unit size, 96 units make up to an inch based on system DPI. But the physical size may not equal to an inch unless System DPI is equal to Screen DPI. To have a comfortable view of the windows, System DPI is always set closely to Screen DPI. So when running on a higher resolution monitor, System DPI is larger and a WPF window keeps its size by rendering it greater detail with more pixels. And a WPF window keeps its size by rendering it with less pixels when the monitor’s resolution is lower.
System DPI: It can be set by Personalize->Display->Smaller-100% (96dpi)/Medium-125% (120dpi)/Larger-150% (144dpi).
Screen DPI: A 19-inch LCD monitor with a maximum resolution of 1600 by 1200 pixels. The screen DPI of the LCD monitor is
4) Declarative User Interface
Except for the traditional ways of designing user interfaces, such as drag and drop control, and code (C#/C++/other languages), WPF provides another way by using declarative markup language XAML. XAML is very easy and convenient just like HTML. What’s more, it allows the designers and developers to work simultaneously, since the design file (.xaml file) and the code file (.xaml.cs file) are two separate files.
5) Style, Resource and Template
WPF provides Style, Resource and Template to modify the appearance of a control. It’s so flexible that developers can get whatever effects they want. What’s more, Style, Resource and Template can be written in a standalone file, so that they can be reused.
6) Routed Event
In traditional windows application, an event is only raised on the control that gets focus. While in WPF, almost all the UI events are routed events. Routed events can depart into Direct Event, Bubble Event and Tunnel Event according to their routing strategy. A Direct Event behaviors like a traditional event. A Bubble Event is raised from the original source (the control focused) to the outermost parent and a Tunnel Event is raised in the opposite direction. Developers can easily stop the routing process by set e.Handled (e is the EventArgs) true. So developers can easily handle or stop one event in any control along the routing path. It’s very useful in many cases, for example setting a global event.
This is a small feature in WPF. In brief, if there are several events that can be used to perform the same function, such as mouse click, shortcut key and menu, developers can bind the events to one command that performs the function instead of writing an event handle for each event.
8) Multimedia and Annotation
WPF provides high-level APIs for using multimedia and annotation, such as audio and video. Developers can easily deal with multimedia and annotation with them and design a wonderful rich application.
Pro WPF 4.5 in C#: Windows Presentation Foundation in .NET 4.5, written by