Getting started with Windows Phone 7
Written by Harry Fairhead   
Friday, 20 August 2010
Article Index
Getting started with Windows Phone 7
How to test WP7?
Using the phone

Banner

Using the Phone

Creating a user interface for WP 7 is more or less the same as creating a Silverlight, or WPF even, user interface.  The only unfamiliar user control is the Application bar and this is very easy to use and much like a standard menu. What is more interesting is the way that you can make use of the built in hardware and software. Using the build in hardware with the emulator is a little tricky at the moment as it doesn't actually emulate many of the facilities. So for a final example, let's write a short application that dials home - yes an ET App.

Start a new project and find a suitable graphic to act as the background for the app. Remember that in a real phone images and other resources would have to be downloaded possibly over the GSM network - so keep things small.

There are many ways to include resources in a project but the simplest is to copy the graphic into the projects main directory and then add the file to the project. Right click on the project folder and use Add Existing Item. Next use the properties window to set the background property of the Grid to the new graphic that you have aded to the project. If you have successfully added the graphic to the project then the graphic will be one of the options automatically offered to you.

 

background

Next place a button on the Grid, change its Content property to read "Phone Home" and size and position it. Finally click on the two default text items and change their content to E.T.App and Phone home respectively.

The final UI should look something like the screen dump:

 

ET1

 

Next we define the code. Double click on the button and you will be transferred to the code editor ready to enter the details of the button click event handler. First we need to create an instance of the PhoneCallTask class:

PhoneCallTask phone = new PhoneCallTask();

To make this work we need to include:

using Microsoft.Phone.Tasks;

at the start of the program. To discover other phone utilities that you can use investigate the Phone.Tasks namespace.

Now that we have the PhoneCallTasks object using it is very easy:

phone.DisplayName= "Home";
phone.PhoneNumber="123 456 789";
phone.Show();

All that happens is that we set the DisplayName property to something sensible and the PhoneNumber property tot he number we wan to dial. Finally calling the Show method makes the Phone Dialler load and display.

The complete code is:

using Microsoft.Phone.Tasks;
namespace WindowsPhoneApplication1
{
Public partial class MainPage :
PhoneApplicationPage
{
// Constructor
PhoneCallTask phone = new PhoneCallTask();
public MainPage()
{
InitializeComponent();
  SupportedOrientations =
SupportedPageOrientation.
PortraitOrLandscape;
 }

private void button1_Click(
object sender, RoutedEventArgs e)
 {
phone.DisplayName= "Home";
phone.PhoneNumber="123 456 789";
phone.Show();
}
}

The initial view of the ET App is very simple looking:

 

ET2

If you click or touch the button in the case of a real phone then you start the process or dialing the number:

 

ET3

 

Of course there are some things we need to do before the App is suitable for deployment - in particular we need to deal with the possibility that it might be suspended and then restarted by the operating system. But this is a simple program for a simple task and this is how it should be. Developing applications for WP 7 is fairly easy and getting easier as the development tools and the class libraries develop.

Look out for more Windows Phone 7 topics in future articles.

If you would like to be informed about new articles on I Programmer you can either follow us on Twitter, on Facebook or you can subscribe to our weekly newsletter.

Each provides a full list of what's new each week - usually five hot book reviews, five thought-provoking articles and five not to be missed news items - in a compact click-to-read form.

 

Banner

<ASIN:0735643423>

<ASIN:1430232161>

<ASIN:0672332221>

<ASIN:0735643350>

<ASIN:1449388361>

<ASIN:0470886595>

<ASIN:1430233060>



Last Updated ( Monday, 20 September 2010 )