Welcome!

Silverlight Authors: Yung Chou, Kevin Remde, Keith Mayer, Jayaram Krishnaswamy, RealWire News Distribution

Related Topics: Silverlight, Wireless, .NET

Silverlight: Blog Feed Post

Writing 'Hello World' Program for Windows Phone 7

Developers can use Silverlight, XNA Framework and of course .NET compact framework for developing applications for WP7

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
The most important files 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 .\HelloWorld\HelloWorld\Bin\Debug 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.. that's all for the HelloWorld application for Windows Phone 7. Future posts will involve more advanced topics. Stay tuned!

Read the original blog entry...

More Stories By Onkar Singh

The author is the founder of 42Gears, developer of affordable Mobile Device Management tools.