Knowledge is power. We love to share it.

News related to Mono products, services and latest developments in our community.

ivan-cagalj

Hello World tutorial for Windows Phone 7

08/22/2011

Windows Phone 7 initial release

Windows Phone 7 is a successor of Microsoft’s old mobile OS called Windows Mobile. It features a new user interface based on Microsoft's Windows Phone design system Metro. Microsoft unveiled Windows Phone in February and the first SDK was made available in September 2010.

Windows Phone Developer Tools includes:

  • Visual Studio 2010 Express for Windows Phone
  • Windows Phone emulator
  • Silverlight 4
  • XNA Game studio 4.0
  • Microsoft Expression Blend for Windows Phone

Developer tools are free to download and install. With Visual Studio 2010 Express Edition as Microsoft’s main IDE and emulator you can write almost any kind of application. You can make visually and content rich applications with powerful Silverlight platform or 3D games with XNA Game studio.

Windows phone 7.1, codename “Mango”

This major update brings a lot of new features and upgrades to Windows Phone 7 platform: new Internet Explorer 9 with hardware acceleration and support for HTML5 to deliver a quick and richer browsing experience, with improved multitasking and fast application switching, social network integration and Windows live messenger and so on. Microsoft has released a new SDK which is currently in beta2. It features background processing, IE9 web browser control, several Live Tile enhancements, direct camera/compass/gyro access, fast application switching, and more. Mango is scheduled for the beginning of this autumn and as the final release of the SDK.

Installation

The installation of Windows Phone SDK is simple and straightforward. Browse here and download the web installer, run it and follow the instructions. Alternatively, you can download its ISO image, mount it and run theinstaller from there. Make sure to check the system requirements. Windows Phone 7 Emulator requires DirectX 10 or higher graphic card with a WDDM 1.1 driver, and it’s supported only on Windows 7 or Vista.

Hello World

After the successful installation, we can start writing our first application. Although SDK features Visual Studio 2010 Express for Windows Phone, I will use Visual Studio 2010 Premium as my primary IDE.

Start Visual Studio 2010 and start a new project by clicking on “New Project” link or Main menu “File -> New -> Project”.



New project dialog is shown.



Left panel features a list of installed project templates. Find “Visual C#”, expand it and select “Silverlight for Windows Phone”.

Our middle section should now contain a list of Windows Phone project templates. Select Windows Phone Application, change application name to HelloWorld and select your project folder. Click OK button and you have created your HelloWorld project.

When our project is loaded, by default MainPage.xaml file is opened in editor. Editor is splitted in two with Windows Phone 7 device designer on the left and xaml code on the right. Notice that there are a few default controls added on the designer surface.



The idea is to create a simple application with one button and a text area, so when button is clicked “Hello World” will be shown inside it. Let’s start by adding a button control. Find button control in the toolbox and drag it to the phone designer. Use visual helpers to position button inside the rectangle that represents content.



Now we can change the button text using the property box. Find Text property end replace text “Button” with “Click Me”.



Same as we did with the button, we can now add a TextBlock control to designer, and resize it to fit the content box. Again, you can use visual helpers to position and align control.



Delete the default text from the  control and leave it empty.



Now our page should look similar to this.



To make “Hello World” text appear when we click on the button we should write some simple code. Double click on the button and wait for a new document to open. 



Edit document by adding a single line of code as shown.



Save the document and hit F5 to start the application. Windows Phone Emulator starts loading and application is then executed inside it. This takes some time if application is started for the first time.

When application is started, you can now see our main page with the “Click Me” button. Click on the button and “Hello World” will be shown.



And that's it, a simple Hello World application created on Windows Phone 7.

Rated 2.22, 9 vote(s). 
By Peter
thanks useful article .
By Madhav
Hi, The link in the statement, "The installation of Windows Phone SDK is simple and straightforward. Browse here and download the web installer..." doesnt work! Please update it. Thanks,.