Skip to content

Writing “Hello World” program for Windows Phone 7

Apr 05, 2010 | 42Gears Team

Windows Phone 7 (WP7) is a cool new mobile platform from Microsoft. Developers can use Silverlight, XNA Framework and of course .NET compact framework for developing applications for WP7.

What do you need

To get started, download and install the following tools on your Windows 7 or Vista PC.

http://www.microsoft.com/downloads/details.aspx?FamilyId=2338b5d1-79d8-46af-b828-380b0f854203&displaylang=en

Installation includes Visual Studio 2010, Expression Blend, Windows Phone Emulator, XNA Game studio along with all the documentation required for writing your next great app.

Note that if Visual Studio 2010 Professional or above is already installed on the PC then only an Add-in for Windows Phone development is installed rather than complete installation of Visual Studio 2010 Express Edition.

To familiarize with the development environment its better to first develop a simple Silverlight application.

Create Hello World Project in SilverLight

1. Launch Visual Studio and Select File -> New Project command.
2. Select SilverLight for Windows Phone as template and Windows Phone Application as project type.
3. Specify HelloWorld as project name and Click OK button.
4. Wizard will create all the necessary files as the foundation for our HelloWorld application.

What Wizard generates

Most important files are generated by the wizard are:
1. MainPage.xaml : Default page with some UI element.
2. App.xaml : This file is used to declare shared application resources like colors, brushes, fonts and various style objects. The code-behind file app.xaml.cs is used to handle global application level events like Application_Startup, Application_Exit and Application_UnhandledException.

Building the Project
Since this is the first application built with the newly installed dev environment, its good to build the default project to rule out any installation problems. Right-click on the Solution in the Solution Explorer and Select Build command.

The build is successful if you will see the following message in the output window.

“========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========”

All is good at this stage. Go to Windows Explorer and browse to .HelloWorldHelloWorldBinDebug folder and you will find HelloWorld.xap which is your actual compiled and compressed Silverlight application.

Lets enhance the program by adding “Hello World” functionality :).

Adding Hello World Stuff

1. Select “My Application” text block in the design view or in XAML view and change it to say, “42Gears”.
2. Select “page title” text block and change it to “Hello World”.

Build the project and a new HelloWorld.xap file will be generated.

Running Hello World Program

Now you are ready to launch the application. Press F5 to start debugging or Ctrl-F5 to Start without debugging. Windows Phone 7 emulator will be launched and HelloWorld.xap will be deployed and your first application will start running on the emulator.

For the first time it will take sometime for the emulator to start. Once its running, you can hit F5 or Ctrl-F5 to quickly deploy and run your application.

Well.. thats all for the HelloWorld application for Windows Phone 7. Future posts will involve more advanced topics. Stay tuned!

Subscribe for our free newsletter

Thank you! you are successfully subscribed.
newsletter

Exclusive News and Updates on Enterprise Mobility!

* I consent to receive newsletters via email from 42Gears and its Affiliates.
Please agree
* I have reviewed and agreed to 42Gears Privacy Policy and Terms of Use prior to subscribing and understand that I may change my preference or unsubscribe at any time.
Please agree
Please verify captcha
Please enter a valid official email