Windows Phone 7 – Call Phone Number from Hyp...
When developing a Windows Phone 7 application with Silverlight, you may want to dial a phone number. To help you accomplish this, Microsoft provides the “Microsoft.Phone.Tasks” assembly. When you reference this component, you can do things like:
- Compose an email (
EmailComposeTask) - Prompt the user to choose an email address (
EmailAddressChooserTask) - Send a text message (
SmsComposeTask) - Perform a search (
SearchTask) - Place a phone call (
PhoneCallTask)
There are more options available in the Microsoft.Phone.Tasks namespace. Still, notice that each of these options ends with the word “Task”. The term “Launcher” is also sometimes used. Regardless of the word, these items interact with the phone’s operating system to do the heavy lifting for you. When you begin a task, it is given the focus and your application gets sent to the background. To demonstrate, imagine that you wanted to call your favorite local restaurant through a HyperlinkButton. As an example, we will add a HyperlinkButton to the inital XAML loaded by Visual Studio when you start a new Windows Phone 7 Silverlight application. The updated XAML will look like the following:
<phoneNavigation:PhoneApplicationPage
x:Class="Sample.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phoneNavigation="clr-namespace:Microsoft.Phone.Controls;
assembly=Microsoft.Phone.Controls.Navigation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="800"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}">
<Grid x:Name="LayoutRoot"
Background="{StaticResource PhoneBackgroundBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--TitleGrid is the name of the application and page title-->
<Grid x:Name="TitleGrid" Grid.Row="0">
<TextBlock Text="SAMPLE" x:Name="textBlockPageTitle"
Style="{StaticResource PhoneTextPageTitle1Style}"/>
<TextBlock Text="phonecalltask" x:Name="textBlockListTitle"
Style="{StaticResource PhoneTextPageTitle2Style}"/>
</Grid>
<!--ContentGrid is empty. Place new content here-->
<Grid x:Name="ContentGrid" Grid.Row="1">
<HyperlinkButton x:Name="myHyperlinkButton" Content="Call Restaurant"
FontSize="22" Click="myHyperlinkButton_Click" />
</Grid>
</Grid>
</phoneNavigation:PhoneApplicationPage>
This XAML will generate an application that looks like the one shown to the right. To make it actually call the restaurant though, we will listen for the user to click the HyperlinkButton. When they click the link, we are going to execute the following code:
When this event handler is executed, the desired phone number (in this case “123-456-7890″) will be sent to the Windows Phone 7 dialer application. This application is launched when the |
|
| This is just a quick introduction to tasks within Silverlight for Windows Phone. The big thing to recognize is that tasks basically start up an application associated with the Phone OS and sends yours to the background. Either way, this post will be updated if the APIs are updated to allow automatic dialing from an application. I hope you found this post valuable. What else would you like to know about Windows Phone 7? |



