Tips, tricks and all the info about Microsoft Visual Studio 2008

Introduction to WPF with Visual Studio 2008

, posted: 10-Mar-2008 09:00

One of the great new features of Visual Studio 2008 is the baked in support for Windows Presentation Foundation (WPF) application development. WPF has been around for some time and shipped as part of Microsoft .Net 3.0. Unfortunately, in order to develop solutions based on WPF you were required to download beta components to snap into Visual Studio 2005.

With Visual Studio 2008, creating high fidelity applications for Windows using WPF is simple.

Create a new project and you will see that WPF Applications are now a first class citizen:



After creating this new project we get a standard project made for us. This project contains a single window that has nothing on it – effectively a blank canvas for creating some cool new application.



There are several things of note when designing your application interfaces. The first is that we can view the application code and the rich WYSIWYG view at the same time with a split view.

This is something new to Visual Studio 2008 and allows developers to see, in real time, their changes to both code and interface. This is hugely beneficial, especially when you are new to WPF development, to see exactly what code is changed when you make a change using the designer.

Speaking of changes, notice the little green block on the side of the text area? That highlights that I have made a change – yellow would mean I had made an unsaved changed while green denotes that this change has now been saved. This has been a nice addition since Visual Studio 2005 but it is certainly worth understanding if you’re new to Visual Studio in general.

Lastly, WPF is a modern presentation framework and therefore everything is vector based. This means that all elements are finitely scalable without losing fidelity. The zoom bar on the left allows us to zoom in and out of our interface fluidly to see how it might look when scaled in, or how it may look on higher definition screens in the future.


The toolbox palette includes many of the controls that developers would expect to see when developing modern applications. Developers can drag and drop these controls onto the form design surface and manipulate their layout.

Once a control is placed on the design surface developers can modify the properties with the properties explorer (shown below) or by editing the UI code (called XAML and pronounced zammel, xaml is an XML based language for declaratively building WPF user interfaces. Visual Studio 2008 understands this syntax and will colour highlight it appropriately).



Here we have set the buttons content property to display the text “Hello World”. WPF is incredibly flexible and most controls can host other controls. This means that we developers can create impressive composite controls with ease. Further to this, the actual style of a control can be separated from the actual instance of the control (similar to how css can be used to style html elements).

WPF allows us to start getting really fancy with rotations and transforms as well. Sure, it is not recommend that you tilt every button in your next application however with the flexibility there you can be sure that you won’t run into some of the challenges that were common in older Windows Forms development.



We should add some code to this application for completeness sakes. For this simple example we want to make it so that the application will close when the button is clicked. To do this, simply double click the button in the designer and the appropriate click event will be stubbed out for us automatically and wired up.
This saves us time and is the same behavior that is found in Windows Forms.



Now when we press F5 and run this small application up we should see a familiar site – an application window – with an unfamiliar one, a fully vector bases, rotated button.

If you are looking at building high end applications to really leverage WPF then I would recommend checking out the Family.Show application built by Vertigo Software here

Having WPF as a first class citizen of Visual Studio 2008 is fantastic for developers – first class tooling support for such an impressive technology is always helpful.

Keep in mind that WPF offers considerably more than we have covered in this article and this only highlights some of the integration points for WPF development in Visual Studio 2008. There is a wealth of information about WPF available online and I would strongly suggest developers start looking at this technology as a replacement for Windows Forms development.

Also, these screenshots are my own and the black background code view is not standard with Visual Studio 2008. If, like me, you like it, then you can easily modify the colours used by Visual Studio under Tools -> Options -> Fonts & Colors.

Download Visual Studio 2008 90 day trial
For detailed information and to request a free 90-day trial DVD of Visual Studio 2008 Team Suite to be sent out to you, go to the Microsoft Visual Studio webpage.

About the Author

John-Daniel Trask is a co-founder of Mindscape, a product development company based in Wellington New Zealand. He also maintains a popular blog about software development and business.

Other related posts:
The Visual Studio 2008 blog is back
Visual Studio 2008 JavaScript Debugging
Windows Workflow Enhancements in Visual Studio 2008








Comment by Shakil Ahmmed, on 15-Dec-2008 23:24

It's very helpful for new programmer. Thank's


About the Visual Studio 2008 Blog

In the years since the hugely successful release of Visual Studio 2005, Microsoft has used developer feedback from all over the world to introduce over 250 new features in the 2008 release.

This sponsored blog will bring Visual Studio 2008 tips and tricks from well known developers in the Australian and New Zealand tech community directly to you.

Make sure you bookmark this blog or subscribe to our RSS feed.



Other blog posts

The New Zealand ALM Conference...
Writing your own Html Helpers ...
Automating Visual Studio 2008...
Windows Azure Table Storage - ...
Windows Azure Table Storage - ...
XML and XSLT in Visual Studio ...
Introduction to New SQL Server...
Using the Visual Studio 2008 P...
Getting started with Windows A...
Why consider sitting for an MC...


Some recent comments

Praveen M on Visual Studio 2008 support for building SilverLigh: I installed SILVERLIGHT TOOLS for VS2008 at my work. I am able to do silverlight...

zefo on Unit testing with Visual Studio 2008: Just minor recommendation: better use *.png for the screenshots. Jpeg is more su...

gil ziny on Unit testing with Visual Studio 2008: When I associate the unit test with TFS testing policy, if fails during check-in...

lynette on Visual Studio 2008 JavaScript Debugging: i have enable in IE the ability to debug scripts. if i go to my section in my c...

Junkie on Why consider sitting for an MCTS or MCP Certificat: The way you presented the case for certification has been completely different f...

Brian Link on Unit testing with Visual Studio 2008: You seem to be incorrect in one of your opening remarks - it seems that web.conf...

Dipanwaya on Unit testing .Net Compact Framework applications w: Steps Behind the Test in the VS 2008? How to test a module in the VS 2008 Envir...

Ricardo on Visual Studio 2008 support for building SilverLigh: Yes! Found the solution myself :) Reset the environment of Visual Web Developer...

Ricardo on Visual Studio 2008 support for building SilverLigh: Have the same problem after installing Visual Web Developer 2008 SP1 and Silverl...

kjward on Automating Visual Studio 2008: thanks lots for all the great info. i'm sure the answer to my question is in th...



Disclaimer

The Visual Studio 2008 blog is sponsored by Microsoft NZ. The blog posts are the authors' genuine accounts of their experiences with Visual Studio 2008 and are not influenced or filtered by Microsoft NZ in any way.