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.
- <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
- <TextBox x:Name="txt_Hello"
- VerticalAlignment="Top">
- </TextBox>
- <Button x:Name="btn_HelloWorld"
- VerticalAlignment="Top"
- Content="Click Me!"
- Margin="0 70 0 0"
- Click="btn_HelloWorld_Click">
- </Button>
- </Grid>
Preview
Double-click on the btn_HelloWorld control to create a click event and add the following lines of code to it:
- private void btn_HelloWorld_Click(object sender, RoutedEventArgs e)
- {
- if (txt_Hello.Text == "")
- {
- MessageBox.Show("Please enter some text in TextBox");
- }
- else
- {
- MessageBox.Show("Hello "+txt_Hello.Text);
- }
- }
Build the solution and run the application in the Windows Phone Emulator.
Final Preview
I hope you like it. Thanks.