The phone call task is used to launch the built-in Phone app and displays the specified phone number and display name.
Note
The phone call is not placed until it is initiated by the user.
The following example demonstrates how to launch the phone call task:
PhoneCallTask phoneCallTask = new PhoneCallTask
{
DisplayName = "Alan Turing",
PhoneNumber = "882960"
};
phoneCallTask.Show();
If the PhoneCallTask.PhoneNumber
is a null or empty string, calling the PhoneCallTask.Show
method has no effect. If the PhoneCallTask.PhoneNumber
has an invalid format, the Phone app prompts the user when the call is being made.
Example code for the PhoneCallTask
can be found in the PhoneCallViewModel
in the downloadable sample code.
The PhoneCallView
allows the user to enter a telephone number and place a call to that number when a button is tapped.
A Place Call button in the view is bound to the viewmodel’s CallCommand
.
The callCommand
field is instantiated in the PhoneCallViewModel
constructor. When executed, the callCommand
creates a new PhoneCallTask
and sets its PhoneNumber
property with the text supplied by a TextBox
in the view, as shown:
public PhoneCallViewModel() : base("Phone Call Tasks")
{
callCommand = new DelegateCommand(
delegate
{
PhoneCallTask phoneCallTask = new PhoneCallTask
{
DisplayName = "someone",
PhoneNumber = phoneNumber
};
phoneCallTask.Show();
});
}
Figure 14.14 shows the PhoneCallView page.
When the PhoneCallTask.Show
method is called, the Phone application is launched, which deactivates the sample application but leaves the sample app’s UI visible in the background (see Figure 14.15).
18.222.21.30