Create Your First Windows Phone 8 Application

In this tutorial, we will learn how to create a first application for Windows Phone 8.

In this article, we will learn how to create a first application for Windows Phone 8. In the previous tutorial, we saw How to install Windows Phone 8 SDK.

Let's begin.

Create a new Windows Phone App



Select Windows Phone OS 8.0 as a target Windows Phone OS for this application and click on OK.



Before starting, let's have a look at the project structure. In Solution Explorer, you will see the structure of the project as in the following:



A Windows Phone Project contains Properties, References, Assetts, Resources, App.xaml, MainPage.xaml and a few additional files. WMAppManifest.xml contains metadata for the application and plays an important role in Windows Phone App validation and certification. The Assets folder contains graphics and icons for the application. The Resources folder contains the file that is used for Localization. The App.xaml file is the starting point of the Windows Phone Application and controls the initializing of the application. MainPage.xaml is the main page that is displayed after launching the application.

Let's change the name of the application and the title of the page. Go to the MainPage.xaml file and change the Text property of the TextBlock control.



I have changed application title to My First Application and Page Title to Hello World.



Find the Grid named ContentPanel in the MainPage.xaml code and add a TextBox and Button control in it.


  1. <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">  
  2.    <TextBox x:Name="txt_Hello"  
  3.       VerticalAlignment="Top">  
  4.    </TextBox>  
  5.    <Button x:Name="btn_HelloWorld"  
  6.       VerticalAlignment="Top"  
  7.       Content="Click Me!"  
  8.       Margin="0 70 0 0"  
  9.       Click="btn_HelloWorld_Click">  
  10.    </Button>  
  11. </Grid>  

Preview



Double-click on the btn_HelloWorld control to create a click event and add the following lines of code to it:

  1. private void btn_HelloWorld_Click(object sender, RoutedEventArgs e)  
  2. {  
  3.    if (txt_Hello.Text == "")  
  4.    {  
  5.       MessageBox.Show("Please enter some text in TextBox");  
  6.    }  
  7.    else  
  8.    {  
  9.       MessageBox.Show("Hello "+txt_Hello.Text);  
  10.    }  
  11. }  

Build the solution and run the application in the Windows Phone Emulator.



Final Preview



I hope you like it. Thanks.