Monday, January 7, 2008

Starting of a brand new day

Till recently, we used to use GDI for 2D viewing. This served its purpose but then when you think about it; all machines nowadays come with a graphics card. The monitors have good resolutions. RAM is inexpensive and so applications can be designed to use more RAM and look better. The need of the hour was a way to use all these advantages and make applications have a better UI than already present and Voila! WPF. Hence WPF is a graphical sub system that uses the DirectX engine for the UI display.

This blog is intended to help beginners start off with WPF. I hope readers will be able to use this as the first step and start churning out applications with such ease that it will shock the developer herself/himself (that was almost profoundJ).

This first section is just to give the background and make readers familiar with the terms and technology and get the basic understanding of WPF. WPF applications can be stand alone or browser applications. Browser applications will be subjected to the usual security (CAS permissions) that all browser apps are subjected to. Here, I talk about stand alone apps which are having full access and are not run in a sandbox.

Prerequisites: The first step would be to get your environment working. You will need the following software which you can find in http://www.netfx3.com/.
1. Microsoft Windows SDK
2. .Net 3.0 Runtine
3. Visual Studio 2005
4. Visual Studio extensions (formerly known as Orcas)

WPF uses XAML (extendable application markup language) to build UI pages (The files will be called filename.xaml). The code for the functionality is written in code behind (filename.xaml.cs) in C# (VB.Net can also be used. But I have worked with C# and hence will be talking only about that). Before we get started on the code, we will need to get familiar with some basic elements.
Imagine a set of goodies (like a bunch of cookies, chocolates, tarts etc) that you need to arrange on a table. So you put them on a tray and on the tray you can arrange them the way you want to. On similar lines, you have controls (like buttons, images, textboxes, labels etc) which need to be displayed on the screen. These controls will have to be enclosed in a container. Containers can be
1. Grid: This container has a rows and columns. You can place controls inside the grid and specify the row and column number. You can imagine something that looks like the image below. You can specify into which cell each element has to go.

2. StackPanel: This container stacks up elements one below the other depending on the order of the controls created.





3. DockPanel: This container places the elements one after the other. The orientation can be changed and it can be made like a StackPanel but usually it is used to place the elements as indicated below.


4. Canvas: This gives you a plain area (as indicated by the name, a canvas) to put any element anywhere. You need to specify the place by giving the number of pixels to the left and top of the canvas.
Now that we have a fair idea about WPF and the terms associated with it, I suggest that the reader read up on articles. http://msdn2.microsoft.com/en-us/library/ms754130.aspx. I have just touched the surface of the whole concept and have intended to give a starting point to the users so that the readers are not intimidated with the ocean of information available on the net. But with the background given here, the information should be a bit more comprehendible. In the next blog, I will explain how to build simple applications and give the steps on how to get our hands dirty.

1 comment:

Amit Mehta said...

Very helpful article for a beginner, a basic understanding of containers is a must for very WPF application, waiting to get my hands dirty :). Keep the high spirits