1. Technology

WPF Tutorial Part 1: A First Introduction to WPF and XAML for Visual Basic

How to get started coding with XAML and WPF


WPF Tutorial Part 1: A First Introduction to WPF and XAML for Visual Basic
Updated May 16, 2014

Microsoft's Technology Firehose

Keeping up with all of the technology changes in .NET is like playing Whack-a-Mole. You're watching one hole and the mole pops up in another.

Something like that happened when Vista, Framework 3.0 and then Framework 3.5 were introduced. What was previously called WinFX was rebranded as Framework 3.0 and actually released along with three huge new libraries, WPF, WCF, and WF. Microsoft used this new technology for Vista and other products, so they had to release and include Framework 3.0 in Vista. But the development tools weren't ready yet, so no Visual Studio based products were released at the same time to use these new libraries.

Although it was released with Vista and provides the power that makes Vista great, WPF is backward compatible with Windows XP as well. XP does need the Framework 3.0 libraries to make it work, and there are a few differences (mainly in how fast and smoothly it runs), but you should be able to run the same WPF application in both environments.

When VB.NET 2008 (also called "VB 9.0") came out, it was introduced with yet another Framework upgrade. Framework 3.5 contained cool new features of it's own such as LINQ. Microsoft has been calling this the "Russian Doll Model" because all features of a previous release are in the next one. (They used to call this "upward compatible".)

The new Framework 3.0 libraries haven't been receiving as much attention as they deserve. Maybe it's because Microsoft has released so much so quickly; maybe it's because a lot of it is a totally new paradigm, and maybe it's because they weren't featured, like LINQ, as part of the VB.NET 2008 launch.

We're going to correct part of that in this article with a VB.NET programmer's introduction to WPF - Windows Presentation Foundation.

Introducing WPF - Windows Presentation Foundation

Microsoft's official site uses the kind of marketing-speak that really leaves you with more questions than answers:

The Microsoft Windows Presentation Foundation provides the foundation for building applications and high fidelity experiences in Windows Vista, blending together application UI, documents, and media content, while exploiting the full power of your computer.

Other than telling you that they used it in Vista, there's not much more information there.

Here's my attempt at something that actually contains information.

WPF is a new graphical subsystem that you can use with the .NET Framework 3.0 and later versions to build applications where the user interface is based on an XML language called XAML (pronounced "zammel") and the code is separate from the design and is based on a .NET language like Visual Basic.

Microsoft (and many others) have concluded that programmers are rotten designers. But standard Windows applications have integrated design and programming. When you build a form, you - the programmer - draw the components and place them on the form. But WPF builds on an idea also used in ASP.NET that makes it possible for the design to be a totally independent responsibility.

Click Here to display the illustration
Click the Back button on your browser to return

For many of us, however, the reality is far different.

Click Here to display the illustration
Click the Back button on your browser to return

This is probably the biggest reason why you - the programmer - need to get up to speed on WPF and XAML. Even if your shop has thoroughly separated the functions, you will still need to know how to interface with the designers.

But the majority of WPF and XAML is mostly design and very little programming. So, even though it is not VB.NET, let's look at it. And ... all code here is based on VB.NET 2008 Express, to be certain that you can use totally free software.

Coding your first WPF app ...

When you start a new VB.NET 2008 Express project, you have two WPF choices in the menu.

  • WPF Application
  • WPF Browser Application

Browser applications are sometimes called "XBAP" applications because that's the file type of the resulting application. They're made to run in a browser and they're preconfigured for ClickOnce deployment. IE 6 and later as well as FireFox 2 have built in support.

WPF Applications are an entirely new and alternative way to create something that will perform very much like a standard Windows forms-based application. But the interface, and the way you build the application, are very different.

So let's start by firing up a new project in VB.NET and selecting WPF Applications. The opening screen looks like this. (A few of the new features have been highlighted.)

Click Here to display the illustration
Click the Back button on your browser to return

It's worth taking a few minutes before doing any coding to just try out the controls and see how it responds. For example, note that if you highlight Grid in the XAML code instead of Window, the design pane tells you that the Grid is precisely 262 by 278 pixels. You can read the values right from the display. You'll notice that the XAML designer in VB.NET gives you a lot more Intellisense help than you get with Windows Forms.

  1. About.com
  2. Technology
  3. Visual Basic
  4. Using VB.NET
  5. How to Get Started Coding With XAML and WPF

©2014 About.com. All rights reserved.