Trying Out Visual Basic for Windows Phone 7

jeffcogswell 1 Tallied Votes 326 Views Share
Manufacturer
Microsoft
Price
Free (but requires non-free Visual Studio)
Pros
Very easy to get up and running with developing for Windows Phone 7. Database features are easy to add as well.
Cons
You can only develop your apps using Silverlight, and can't use XNA (even though you have to download XNA Game Studio with it). Further, there's not yet a free version available, so you have to have one of the paid versions of Visual Studio 2010.
Summary
The Visual Basic for Windows Phone 7 tools are just what you would expect from Microsoft -- they integrate right into Visual Studio and are very easy to use, as long as you're willing to limit yourself to Silverlight-based apps on the phone.
Rating

Last week, Microsoft released a set of tools for developing software for the new Windows Phone 7 using Visual Basic. In order to use the tools, you have to have Visual Studio 2010 Professional or better (right now the Express versions don't work, although I've heard that will change).

But here's the catch: You're coding for Silverlight. You're building Silverlight apps that run on Windows Phone 7. However, that's not necessarily a bad thing. Normally I have my reservations about Silverlight in browsers on desktops, because that's just one more runtime that needs to be downloaded and installed next to, for example, Flash, Java, and all that. And while there are versions of Silverlight for Linux (called Moonlight), those versions are always a bit behind, making it hard to ensure that your Silverlight application runs in all browsers on all platforms. But in the case of Windows Phone 7, that whole issue goes away: You're writing an application just for Windows Phone 7, which has Silverlight built right into it.

Nevertheless, on a recent job, I had to develop a set of Silverlight apps, and I have to say, even though I have the concerns I just mentioned, it's great to program for. If you've done any ASP.NET programming, you'll feel very much at home. You use a declarative syntax similar to ASP.NET for laying out your GUIs, a syntax called XAML (pronounced Zamel, rhymes with Camel). And then you attach code to them, where you can use either VB.NET or C#.

The tools come with five project templates for Visual Studio, all found in the VB section. Here's a picture of it, followed by explanations:

Windows Phone Application: This is a basic starting point for a general-purpose application. Windows Phone Databound Application: This is a starting point for building database applications. You can start with the previous template, Windows Phone Application, to build database applications, but this one has some database starter code that helps you get going. Windows Phone Class Library: Just what it says, a class library that you can use in other apps you're building. Windows Phone Panorama Application: This is a starting point for creating panoramic applications, which are apps that extend horizontally beyond the bounds of the screen, allowing users to slide the frame left and right. On the side you'll see a little thumbnail of what's off the screen. Typical uses are things like photo apps. (This is hard to explain in a single sentence, so if you're interested, check out the links at the end of this article.) Windows Phone Pivot Application: This is a starting point for pivot applications. Pivot apps are similar to panorama applications, but are more for data. And again, I provide links at the end of this article for more information. When you create a new project from the Windows Phone Application template, you get a starting XAML page, which is a type of XML used for declaring Silverlight GUIs. The toolbox in Visual Studio includes a whole set of Silverlight controls that provide the basic GUI tools found in most applications: buttons, radio buttons, checkboxes, listboxes, and so on. The whole setup works just like you would expect in Visual Studio; you drop the controls from the toolbox on your form, and then add code for your event handlers.

Here's what Visual Studio looks like when I first created a Windows Phone Application and then dropped a button on the form:

Then I double-clicked the button. Visual Studio inserted an event handler for the button's Click Event, which looks like this:


I then added a call to MessageBox. Here's the whole subroutine; Visual Studio created this code automatically except for the MessageBox line, which I wrote:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click
        MessageBox.Show("Click!")
    End Sub

Next I was able to run the application within an emulator right on my PC. Here's what it looked like:

When I clicked the button in the app, the call to MessageBox took place, looking like this:


The Silverlight apps on Windows Phone 7 support the data binding syntax that was introduced in version 2.0 of Silverlight. This means you can automate data binding without having to write much VB code. Instead, you just specify in the XAML file where your data is, and then attach that data to your controls. The controls will then automatically display the data. It's pretty easy and very straightforward.

The Windows Phone Databound Application template is a starter for just such a data-driven app. When you use this template, you get a listbox that's bound to some sample data. The sample data is just a list filler text in a fake Latin-like language, but it demonstrates the basic concept. You can use this as a starting point for your own data-driven application.

The whole aspect of programming in Silverlight isn't new here, so if you already know Silverlight, you'll be good to go. And further, C# development has already been available for Windows 7 for a few months. So the only new part, really, is that you can now use VB.

But so far, you can't do as much as you can with C#. If you use C#, you can go outside of Silverlight into other areas such as XNA, which is a platform for developing games. But if you're willing to work within the confines of Silverlight, you'll have everything you need.

But this is bizarre: To download the tools, first you have to install the Windows Phone 7 development kit. With that comes a whole set of tools you may or may not need, including Microsoft XNA Game Studio 4.0, which only supports C#. The rationale is (apparently) that to develop for the phone you can use either Silverlight or XNA – if you're using C#. So all the C# tools come with the download. But you can't use VB inside XNA Game Studio, so if you're only interested in VB, you have to get this extra tool anyway. That's kind of a waste. But on the other hand, if you want to move to C# and XNA, then you'll be good to go.

So if you're ready to give it a spin, and you already own the full version of Visual Studio, then here's where you can download it. First, you'll need the Windows Phone Developer Tools that I mentioned: http://www.microsoft.com/downloads/en/details.aspx?FamilyID=04704acf-a63a-4f97-952c-8b51b34b00ce&displaylang=en

Then you can download the Visual Basic for Windows Phone Developer Tools, which is the tool itself:

http://www.microsoft.com/downloads/en/details.aspx?FamilyID=4e97ea70-e479-4c05-814f-639d71690e5d&displaylang=en

Finally, if you're interested in learning more about those two project types I mentioned, panoramic and pivot, then here's where you can find a couple of good rundowns.

Panoramic applications: http://msdn.microsoft.com/en-us/library/ff941104(VS.92).aspx .

Pivot applications: http://msdn.microsoft.com/en-us/library/ff941098(VS.92).aspx .

And here's a blog post that talks about the two. This post is based on an earlier pre-release of the tools, but the concepts are the same: http://www.jeff.wilcox.name/2010/08/looking-ahead-at-panorama-and-pivot .

All in all, I was pretty impressed with how easily I was able to get up and running. My personal preference is C# over VB.NET, so I'd be more inclined to use the other tools. And at present, since these only work with the full Visual Studio, you can't do this for free.

kvprajapati commented: Good article. +11
cooley_l 0 Newbie Poster

I've just an evaluation version of Microsoft Visual Studio 10 Pro and the VB tool installed
w/o a problem.

jeffcogswell 175 Light Poster Featured Poster

Good point! The eval version should work just fine. Thanks for the tip!

Jeff

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.