×
Namespaces

Variants
Actions

Simple WP7 Application using Visual Studio Express

From Nokia Developer Wiki
Jump to: navigation, search
WP Metro Icon Tools.png
SignpostIcon XAML 40.png
SignpostIcon WP7 70px.png
WP Metro Icon Baby.png
Article Metadata
Compatibility
Platform(s): Windows Phone 7 only
Windows Phone 7.5
Article
Created: girishpadia (27 Jun 2011)
Last edited: hamishwillee (04 Jul 2013)

Contents

Introduction

Nokia has announced a new device 'Mango' with the first Windows Phone OS. With this announcement, Nokia has opened the door for the developer community to start the work over Windows Phone. Here, in this example, We will see two basic elements; a Textbox and a Button, mostly used while developing any application on Window Phone. The simple demostration shows a textbox and a button, which will show the value of text box as a MessageBox.

What you need?

You need to download and install Windows Phone SDK which is available to download from the Category:Windows Phone. Remember that Windows Phone SDK require Windows Vista or Windows 7 Operating system to install.

Getting Started

Once you install Windows Phone SDK, goto Start->Microsoft Visual Studio 2010 Express->Microsoft Visual Studio 2010 Express->Microsoft Visual Studio 2010 Express for Windows Phone. You will see the application as shown in below figure. Article 1 wp image 1.jpg

Goto File Menu-> New Project You can see on the left hand side of the dialog box showing the installed templates. You can select Visual Basic or Visual C# to use as your programing language. Here I am selecting Visual C# and "Silverlight for windows phone" under this category. Give the Project Name of your wish. e.g. "MyFirstApplication". Also select location where you wish to save the project. Please refer the following dialog box for the reference.

Article 1 wp image 2.jpg

As soon as you will click on OK button it will ask you "Target Windows Phone version". Select "Windows Phone 7.1" or "Windows Phone 7.0" The following screen gives small idea of the basic screen.

Article 1 wp image 3.jpg

Placing the controls on the layout.

click on Toolbox and place "Textbox" and "Button" controls in the phone layout as shown in the following figure. You can set height and width of both the control as per your wish. Change the property for both the control as follow. You can discover more important preperties also.

Control Property to change Value to set
TextBox Text Blank
TextBox Name txtName
Button Text Show Value
Button Name btnShowValue

Article 1 wp image 4.jpg

On Click event

So far we have placed the controls and set the appropriate properties. Now double click on Button control we just placed on the phone layout. You will see code view where you can write actual code. Place the following code.

        private void btnShowValue_Click(object sender, RoutedEventArgs e)  
{
MessageBox.Show("Hello " + txtName.Text);
// MessageBox.Show is used to popup a message box with the text within the brackets. "+" sign is used to
// show string concatenation in C#
}
// You can use "//" or " /*...........*/ to comment the text

Run the program

As soon as you run the application, You can see the Windows Phone Emulator to test the application. Following screen shows two different states of running above application.

Article 1 wp image 5.jpg

Tested On

Windows Phone Emulator

This page was last modified on 4 July 2013, at 08:30.
117 page views in the last 30 days.