Over a million developers have joined DZone.

Windows Phone 7 Hello World Application

DZone's Guide to

Windows Phone 7 Hello World Application

· Mobile Zone ·
Free Resource

In this tutorial I am going to create a very simple “Hello World” Windows Phone 7 application (check image bellow). Hopefully, after this lesson you will be skilled enough to develop your own application.

Windows Phone 7 Hello World by eugenedotnet

For this tutorial you will need Visual Studio 2010 with Windows Phone Developer Tools installed (including Emulator). You can download those tools from here (or simply search for “Windows Phone Developer Tools”).

After you successfully installed WP7 Developer Tools, it is time to open Visual Studio 2010 for the first time and create a new project.

Creating new project

First of all you need to create a new project. To do so open Visual Studio 2010 -> File -> New Project -> select Windows Phone Application in dialog as it is shown on picture bellow. Other project templates I will cover later.

eugenedotnet creating windows phone 7 project for application bar

What are the key files in newly created solution?
Manifest file – contains meta-data of an application. You can find more information about it here.
App.xaml – contains all general resources and properties of Windows Phone 7 Application. It also contains Execution Model events.
MainPage.xaml – this Windows Phone Page is launched by default. You can change the default page by modifying NavigationPage attribute of DefaultTask element in Manifest file.

Modifying XAML

Next you will need to modify MainPage XAML. Basically, you can add new UI elements to XAML using drag-and-drop from Toolbox or by adding them to XAML markup by hand. As for me, I find the second way more appropriate for development (of course, it is also possible to add elements programmatically, using C# managed code). After adding a textblock and a button (this time I’ve used drag-and-drop) my MainPage XAML looked like that:

    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
    <!--LayoutRoot contains the root grid where all other page content is placed-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        <!--TitlePanel contains the name of the application and page title-->
        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="24,24,0,12">
            <TextBlock x:Name="ApplicationTitle" Text="EUGENEDOTNET.COM" Style="{StaticResource PhoneTextNormalStyle}"/>
            <TextBlock x:Name="PageTitle" Text="my first app" Margin="-3,-8,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
        <!--ContentPanel - place additional content here-->
        <Grid x:Name="LayoutRoot" Grid.Row="1">
            <TextBlock Height="36" HorizontalAlignment="Left" Margin="113,106,0,0" Name="textBlock1" Text="MyText" VerticalAlignment="Top" Width="156" />
            <Button Content="Say Hello!" Height="70" HorizontalAlignment="Left" Margin="113,180,0,0" Name="button1" VerticalAlignment="Top" Width="179" Click="button1_Click" />


Handling events in code

As some of you have probably noticed I’ve added a click event for my button control. Now I need to add an event handler for that in code (MainPage.xaml.cs). Clicking the button on MainPage will fill textblock with “Hello World!” string. Check code bellow:

public partial class MainPage : PhoneApplicationPage
    // Constructor
    public MainPage()
    private void button1_Click(object sender, RoutedEventArgs e)
        textBlock1.Text = "Hello World!";

Running the application

That’s it. Our first Windows Phone 7 application is ready. Just press F5 to run the application in Debug mode. Make sure that “Windows Phone 7 Emulator” is selected as a target for Silverlight for Windows Phone projects.

My previous “Hello world” webcast (Spring, 2010). I am still keeping this memory of mine alive :)



Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}