Visual Basic Tools for Windows Phone 7 Developers

Introduction

When Microsoft released the first CTP of development tools for the Windows Phone 7 Platform, Visual Basic developers were left in the lurch since the first round of tools targeted only C# programming.

Luckily for WP7 developers, Microsoft released a CTP version of the Visual Basic tools in September. These tools finally received to go-live status when the RTM version of the tools were declared on 29th November 2010. With the tools release, VB developers could also harness their existing skills to developer Silverlight based applications for the Windows Phone 7 platform.

Differences Between the C# Tools and VB Tools

While Microsoft maintains parity w.r.t. development tools for most of its platforms, for Windows Phone 7, there seems to be a limitation for VB developers. VB developers at the time of authoring this article could only write Silverlight based applications for the Windows Phone 7 platform. XNA for Windows Phone 7 support is currently not available for VB developers.

Where to get the Visual Basic Developer Tools

Developers can get the VB version of the developer tools from http://go.microsoft.com/fwlink/?LinkId=206790.

If you have the CTP version of the VB tools, it is better if you uninstall the tools and install the RTM version of the tools.

Prerequisites

VB tools for WP7 require that Microsoft Visual Studio 2010 Professional or higher version of the VS engine is installed. It also needs the RTM version of the C# development tools for the Windows Phone 7 tools installed. This is because the VB version of the development tools piggy-back on the C# tools. Also, the VS 2010 Express SKU is not supported for Windows Phone 7 development.

Getting Started with VB development for Windows Phone 7

To get started with creating a Visual Basic Silverlight application for Windows Phone 7, fire off Microsoft Visual Studio and select the "Silverlight for Windows Phone" group of templates under Visual Basic.

Windows Phone 7 group of templates under Visual Basic.
Figure 1

Here we notice that there are 5 different templates for WP applications.

Let us understand the purpose of each:

TemplatePurpose
Windows Phone 7 applicationFor a simple Window Phone application
Windows Phone 7 Databound applicationFor a WP application which is highly data dependent
Windows Phone 7 Class LibraryTo create a DLL equivalent for WP applications
Windows Phone 7 Panorama applicationFor creating a WP application with a Panorama View
Windows Phone 7 Pivot applicationFor creating Pivot control based WP applications

For our case, we will create a simple WP application called WPVBDemo.

Let us create a simple VB application which adds a couple of numbers. How exciting?

To do this, let us drag and drop a couple of textblock controls, a couple of textbox controls and a button control.

Let's give our application a highly evolved name called the "My Magnificent Calculator" After you are done designing the application, the XAML should look something like this.

XAML Code Example
Figure 2

Now, let us go about wiring the events when you do some actions on the application.

The first thing we will do is ensure that the Sum is calculated when we click the Calculate button. On the VB designer, double click the Calculate button and we will be automatically transferred to the event handler for the Click event for the button "Calculate".

Here, add the highlighted code.

       Private Sub ButtonCalculate_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles ButtonCalculate.Click
           Dim sum = 0
           Dim int1 = Integer.Parse(TextBox1.Text)
           Dim int2 = Integer.Parse(TextBox2.Text)
           sum = int1 + int2
           TextBlockSum.Text = sum
   
   
       End Sub
 

Similarly for the Clear button, we need to ensure that we clear up the contents of the textboxes.

The code for the Clear Click Event handler is below:

       Private Sub ButtonClear_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles ButtonClear.Click
           TextBox1.Text = 0
           TextBox2.Text = 0
           ButtonCalculate_Click(Nothing, Nothing)
   
       End Sub
 

Now, we can simply "F5" to start debugging our application in the Windows Phone 7 emulator. If this is your first time running the Windows Phone 7 emulator, it will take some time to load and launch the emulator. To converse time for subsequent debugging, remember to "stop debugging" from Microsoft Visual Studio rather than shutting down the emulator. It will help speed up the performance by taking only a few seconds to deploy the XAP file to the emulator to run it.

If all is well and you don't get any compile errors you will see the application running on the Windows Phone 7 emulator. Enter "4" and "6" in the two text boxes and click "Calculate" to see our application perform the complex operation of adding two numbers.

If you run into issues writing code, you can check the code snippet available for download as an accessory to this article which contains the code you need to run the application.

Summary

In this article, we saw that Visual Basic is now a first-class citizen when it comes to developing Silverlight based applications for Windows Phone 7. Hopefully, you will now have a chance to re-use the Visual Basic acumen you already possess to author some great applications for the Windows Phone 7 platform.

Related Articles



About the Author

Vipul Vipul Patel

Vipul Patel is a Software Engineer currently working at Microsoft Corporation, working in the Office Communications Group and has worked in the .NET team earlier in the Base Class libraries and the Debugging and Profiling team. He can be reached at vipul_d_patel@hotmail.com

Comments

  • There are no comments yet. Be the first to comment!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

  • Live Event Date: November 13, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT APIs can be a great source of competitive advantage. The practice of exposing backend services as APIs has become pervasive, however their use varies widely across companies and industries. Some companies leverage APIs to create internal, operational and development efficiencies, while others use them to drive ancillary revenue channels. Many companies successfully support both public and private programs from the same API by varying levels …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds