Subscribe:Posts Comments
Share |

You Are Here: Home » Programing, Uncategorized » Windows Phone 7 – My First Phone App!

After much procrastination, I started to create my first Windows Phone 7 application this week. To be honest I did not think it would be an easy task given that it has been quite a while since I last opened visual studio to code something(much of my time has been spent admiring apps written by the amazing Imagine cup competitors;-)). Well, but I decided to take the plunge, and to my complete surprise I wrote my first app in flat 15 minutes.

Hence this blog post, coz I believe my example should inspire several others to start writing apps for the new and upcoming Windows Phone 7 platform using cool technologies such as Silverlight and XNA.

Let me walk you through the steps I took to get started –

1. The first thing I had to do was of course to download the much talked about tools for Windows Phone 7. It was a totally painless experience to download and run the setup on my Windows 7 PC. The set up installed the following components for me in less than 5 minutes.

  • Visual Studio 2010 Express for Windows Phone Beta
  • Windows Phone Emulator Beta
  • Silverlight for Windows Phone Beta
  • Microsoft Expression Blend for Windows Phone Beta
  • XNA Game Studio 4.0 Beta

clip_image001

Run the vm_web.exe to start the set up.

2. Once I got the tools, I had to think of the application idea that I wanted to work on, since this was my first app I decided to take a really simple app. The app basically shows up the various taxi services in Singapore and helps you directly dial the numbers without having to remember them when you need it. I find the concept very helpful when you are in rush and cant remember the numbers of the various taxi providers.

3. You can follow the following steps to recreate this app on your own:

a) Open Visual studio 2010 Express for Windows Phone, click on New Project and select Silverlight for Windows Phone and Windows Phone Application(remember Silverlight and XNA are the two key technologies required to build apps for Windows Phone 7).

clip_image003

b) The project gets created with the skeleton Silverlight based-phone app content, like any Silverlight application, the code contains a mainpage.xaml file. For first timers to Silverlight, XAML is the markup language used to define the user interface of Silverlight apps. It has a .CS file associated with it that defines the server side code. XAML has various types of controls for you to use, one of which is the GRID control, think of it like the HTML <Table> tag. Look  through the XAML file and familiarize yourself with the basic structure.

clip_image005

c) Navigate to the TextBlock inside the StackPanel which is named “applicationtitle”  and change the text property to “My First Phone App” or what ever else you'd like.

clip_image007

Similarly you can change the PageTitle to “Call a Cab!!”.

clip_image009

d)Now you need to add in other controls to populate the main Grid -

1
2
3
<!–ContentPanel – place additional content here–>
<Grid x:Name=“ContentGrid” Grid.Row=“1″>
</Grid>

We need to define the rows and columns inside this main Grid, For now I am just adding 1 one row with 2 columns -

1
2
3
4
5
6
7
8
9
10
11
12
13
<!–ContentPanel – place additional content here–>
<Grid x:Name=“ContentGrid” Grid.Row=“1″>
<<strong>Grid.RowDefinitions> </strong><strong>
<strong><RowDefinition Height=“Auto”></RowDefinition></strong>
<strong></Grid.RowDefinitions> </strong></strong><strong></strong>

<strong><Grid.ColumnDefinitions></strong>
<strong><ColumnDefinition></ColumnDefinition></strong>
<strong><ColumnDefinition></ColumnDefinition></strong>
<strong></Grid.ColumnDefinitions> </strong><strong>
<strong></Grid></strong></strong>

<strong><strong>

Adding in an image in the first column and a button in the second column but first need to add an image file to the project -

clip_image011

Updated Grid Control code -

1
2
3
4
5
6
7
8
9
10
11
12
<!–ContentPanel – place additional content here–>
<Grid x:Name=“ContentGrid” Grid.Row=“1″>
<Grid.RowDefinitions>              �
<RowDefinition Height=“Auto”></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<strong><Image Source=“Toyota_Crown_Comfort_2.jpg” Width=“150″ Grid.Column=“0″ Grid.Row=“0″ Height=“80″ RenderTransformOrigin=“0.592,0.5″/></strong><strong>
<strong><Button VerticalAlignment=“Top” Height=“70″ Grid.Row=“0″ Grid.Column =“1″ Content=“Comfort Taxi” Margin=“0,0,28,0″ Background=“#FF7600FF”/></strong>
</strong></Grid>

Now, associating an event handler at the click event of the button control -

1
<Button VerticalAlignment=“Top” <strong>Click=”Button_Click”</strong> Height=”70″ Grid.Row=”0″ Grid.Column =”1″ Content=”Comfort Taxi” Margin=”0,0,28,0″ Background=”#FF7600FF”/>

Double click the button on the design pane of the xaml file and it will take you to the code behind .CS file.

Add the namespace,  Microsoft.Phone.Tasks in the .CS code behind file. The statement would look like this –

using Microsoft.Phone.Tasks;

Inside the event handler Button_Click, add the following three lines of code and we are done.

1
2
3
4
5
6
7
private void Button_Click(object sender, RoutedEventArgs e)
{
PhoneCallTask call1 = new PhoneCallTask();
call1.PhoneNumber = “65521111″;
call1.Show();

}

Build your application by keying in Control +F5 and that will launch the emulator and load your application onto it -

clip_image013

Click on the Comfort Taxi button and that will prompt you with a dial screen that dials the number of the taxi provider.

So far its a very basic structure of this app, obviously you can improvise here in many ways – by adding more taxi providers, by improving the user interface(I am not that artistic), by not hardcoding the taxi numbers but reading it from a stored file or something. Feel free to use these steps to get started Smile.

Happy Windows Phone 7 programming!!

© 2010 Bilcyber.com · Subscribe:PostsComments · Designed by Billy Wirawan ·