Desktop-as-a-Service Designed for Any Cloud ? Nutanix Frame
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
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.
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.
Here we notice that there are 5 different templates for WP applications.
Let us understand the purpose of each:
|Windows Phone 7 application||For a simple Window Phone application|
|Windows Phone 7 Databound application||For a WP application which is highly data dependent|
|Windows Phone 7 Class Library||To create a DLL equivalent for WP applications|
|Windows Phone 7 Panorama application||For creating a WP application with a Panorama View|
|Windows Phone 7 Pivot application||For creating Pivot control based WP applications|
For our case, we will create a simple WP application called
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.
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.
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.