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.
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" />
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 = 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.
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;
Following screenshots depict the same :
Download source code File:WP MakeACall.zip.
Basically PhoneCallTask API allows to launch the Phone application.
- PhoneCallTask (MSDN)