ABC Of WPF

While working on .NET/SQL for project requirements, I went through the WPF. I visited so many online tutorials and videos to get the knowledge. In this article, I am going to share my understanding with you.

In this article I will explain why we use WPF and why it's better than other Windows applications.

I have also uploaded the samples which are like a PPT and are created using WPF technology so that it will impart more knowledge.

Why is WPF best over Windows applications?

WPF stands for Windows Presentation Foundation. WPF was first introduces in .NET framework 3.0 version after that so many other features were added in the subsequent .NET framework versions.

Windows Presentation Foundation (WPF) is Microsoft's next-generation UI presentation system for building Windows client applications and visually rich user experiences. With WPF, one can create a wide range of both standalone and browser-hosted applications. An example is Yahoo! Messenger.

WPF is a combination of applications with rich UIs, 2D graphics, 3D graphics, documents and multimedia into one single framework. Its vector based rendering engine uses hardware acceleration of modern graphic cards. This makes the UI faster, scalable and resolution independent.

WPF

WPF is superior over win forms due the its ABCDEFG features

  1. A -->Any where Execution (XAML)
  2. B -->Bindings
  3. C -->Common Look and Feel (Styles)
  4. D -->Directive Programming
  5. E -->Expression Blend and Animation
  6. F -->Faster Execution (Hardware Rendering)
  7. G -->Graphics Independency (DIP)

A -->Any where Execution (XAML)

Anywhere execution means once you design your UI in WPF, use it in either WPF Windows applications or Browser based application. You must be wondering how it is possible to working fine in multiple environments. The internal representation of WPF UI is XML (Extensible Markup Language). Think about WCF Services/Web Services.

All these have internally based XML. We know XML is platform independent and works fine both in homogenous or heterogeneous platform.

Suppose you have created a web service in WCF you can either use it in C# Application or Java Application. It will work fine in both platforms.

WPF

B -->Bindings

WPF provides a simple and powerful way to auto-update data between the business model and the user interface. This mechanism is called DataBinding.

Every time when the data of your business model changes, it automatically reflects the updates to the user interface and vice versa. This is the preferred method in WPF to bring data to the user interface.

Here is an example that on change of text property in textbox1 it automatically changes the value in textbox2. If we think such in windows application then we have to write code in textchannged event of each textbox controls. But in WPF it can be done easily using binding property. No need to writing more and more codes for each textbox controls.

C -->Common Look and Feel (Styles)

One Major benefit over win form is Styling. Suppose you want to create an application with a unique design. All your textboxes should have an orange background and an italic font. Doing this in a conventional way means that you have to set the Background and the FontStyle property on every single textbox. In winforms you have to set the properties of each textbox.

But in WPF just create a style and apply this to all textboxes only. Later we want to change in styles just change there and automatically changes will reflect in all textboxes.

D -->Directive Programming

We have just seen how easily we handled the text changed event. What we did is we just bound the Binding property to the Source and Destination controls. This is called Directive Programming. The WPF auto handles the events and renders the values to target controls. We need not to bother for it.

E -->Expression Blend and Animation

Animation is another major benefit of WPF. Think about 2D/3D programming in Win form, for this we have to integrate DirectX programming with Win form. DirectX internally deals with 2D/3D programming. Here in WPF the Directx is internally part of its architecture.

Expression Blend in WPF UI Designer tool is used for design the rich UI Design. Expression Blend is the tool for designers. It's part of the Expression Studio, a new tool suite from Microsoft especially created for user experience designers. Blend covers all the missing features of the Visual Studio designer like styling, templating, animations, 3D graphics, resources and gradients. It also separates the Designing and Coding standalone.

F -->Faster Execution (Hardware Rendering)

One major benefit over win form is faster execution. As I said WPF internally uses DirectX which performs Hardware rendering whereas Win form uses GDI (Graphical Data Interface) which performs software rendering.

Now the question arises what are Hardware Rendering and Software Rendering? Computer renders the display on the monitory either by CPU or GPU. CPU is the heart of computer. It does all the works and starts from memory management/Application Execution/Operating System Management to rendering display on the Monitor.

GPU (Graphical Processing unit) is a special kind of processor which is made for only rendering the display on the screen. It leaves the CPU to do this work like Memory Management, Application Execution, and Disk Management etc. In case where GPU is not found then it moves to CPU.

Hence in Software rendering it takes much time in respect of hardware rendering.

In further the WPF Rendering can be classified into three parts,

  • Tier 0
    When DirectX does not find GPU in the computer. It switches to CPU and uses DirectX 7 to renders on the monitor. It is purely Software Rendering.

  • Tier 1
    When DirectX finds GPU in the computer, it uses DirectX 7-9 to renders on the monitor when it sees some of the functionalities are better drawn by GPU and some of them are drawn by CPU. It is partial Hardware Rendering because Software rendering also performed.

  • Tier 2
    When DirectX finds GPU in the computer, it uses DirectX 9 to renders on the monitor when it sees the functionalities than can only be better drawn by GPU. It is purely Hardware Rendering.

    WPFWPF

G -->Graphics Independency (DIP)

The graphics independency means resolution independency. Resolutions mean the number of pixels displayed on the screen. Pixels are small dots on the screen. Pixels determine the resolution of the screen. In the below examples we have the same dimension of resolution on the two screens but the size of screen is different. It means some pictures display better in smaller monitors. It may not be the same display in larger monitor. The picture may be distorted. Because the larger screen would have less density of pixels on the screen and the screen has to adjust as per the screen resolution. 

WPF

But it WPF we don't see such issues. It won't use pixels as display measurements.

WPF works on DIP (Device Independent Pixel) 1 DIP=1/96 th of Inch. It basically relates itself directly with the size of screen.

Now you know the benefits of WPF over win forms. All the WPF runs with the mentioned benefits. Now we are going to start the WPF segment in details.

This chart shows how WPF is more beneficial.

WPF

Up Next
    Ebook Download
    View all
    Learn
    View all