How to make a call in Windows Phone 7
This code example shows how to launch the Phone app using PhoneCallTaskAPI in Windows Phone 7.
Article Metadata
Code Example
Tested with
Compatibility
Article
Introduction
This simple example displays a Phone Call button on the screen. When the button is pressed, the app calls PhoneCallTaskAPI in the Microsoft.Phone.Tasks namespace.
First create a new Windows Phone 7 Silverlight application using the default template in MS Visual Studio. Then add a Button to the XAML as shown below:
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Button Content="Phone Call" Height="82" HorizontalAlignment="Left" Margin="140,234,0,0"
Name="btnCall" VerticalAlignment="Top" Width="auto" Click="btnCall_Click" />
</Grid>
The user interface with the button is shown below:
Next initialize the PhoneCallTask task object in the constructor of page. To avoid the memory overhead so I initialized in the constructor.
PhoneCallTask phoneTask = null;// Constructor
PhoneNumberChooserTask phoneNumberChooserTask;
public MainPage()
{
InitializeComponent();
phoneNumberChooserTask = new PhoneNumberChooserTask();
phoneNumberChooserTask.Completed += new EventHandler<PhoneNumberResult>(phoneNumberChooserTask_Completed);
phoneTask = new PhoneCallTask();
}
The PhoneCallTask class contains two core properties like DisplayName, PhoneNumber and one show() method, which allows us to show the phone application. To make an actual call though the application.
Double-click the button control and click event handler got added to button control object.On the button click event the device's native phonebook is launched & user can then select a contact from it to whom he wishes to make a phone call . See below mentioned code snippet.
private void btnCall_Click(object sender, RoutedEventArgs e)
{
//this will launch the phonebook to choose a contact to call.
phoneNumberChooserTask.Show();
}
As soon as user chooses the contact from phonebook, the following call back method gets called & launches the phone call dialog, asking the user to dial the particular contact or not
void phoneNumberChooserTask_Completed(object sender, PhoneNumberResult e)
{
if (e.TaskResult == TaskResult.OK)
{
//Code to start a new phone call using the retrieved phone number.
phoneTask .DisplayName = e.DisplayName;
phoneTask .PhoneNumber = e.PhoneNumber;
phoneTask .Show();
}
}
Following screenshots depict the same :
Download source code File:WP MakeACall.zip.
Summary
Basically PhoneCallTask API allows to launch the Phone application.
References
- PhoneCallTask (MSDN)





Hamishwillee - Pavan, Vineet
Vineet, thanks for adding the note comparing to Symbian. I think this is very important, so much in fact that I've moved it to the top under the Abstract. Note that when you post text, please have a look at how it renders - the text you had originally had lots of odd spaces - ie "this is blah , blah" - note the space before the comma, this should not exist.
Pavan. Nice article. I have subedited it slightly for readability. In addition I've linked to the namespace and the PhoneCallTaskAPI in MSDN reference in the Abstract. Please consider doing this in future. At the moment this hard codes your name, which looks great. It would be excellent if you could extend this to get the contact details to call from the contacts store (or Facebook or whatever).
Cheers
Hhamishwillee 01:22, 20 February 2012 (EET)
Vineet.jain - Hamish - Sure
Surely Hamish i'll keep this in my mind for future edits.
Thanks
Vineetvineet.jain 07:52, 21 February 2012 (EET)
Rocking.ships - Thanks
Thanks buddy!rocking.ships 22:38, 24 November 2012 (EET)