Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

如何使用Windows Phone 7打电话

From Wiki
Jump to: navigation, search
WP Metro Icon MobilePhone.png
SignpostIcon XAML 40.png
SignpostIcon WP7 70px.png
Article Metadata

兼容于
文章
翻译:
WS_YiLunLuo
最后由 hamishwillee 在 17 Jul 2013 编辑

本文描述了如何使用托管API在Windows Phone上打电话。

简介

本文的目的是为了以编程的方式打电话,有时应用程序有这样的要求。在这种情况下,我们使用Microsoft.Phone.Tasks命名空间下的PhoneCallTask来打电话。 举个例子,我们通过自己的应用程序拨打电话。创建一个新的 Windows Phone Silverlight应用程序,添加一个按钮到Visual Studio生成的默认的XAML页面,

<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>

XAML将会产生一个如下所示的UI。

01.png

现在初始化PhoneCallTask,为了防止溢出内存,在构造函数中进行初始化。

PhoneCallTask phoneTask = null;// Constructor
 
public MainPage()
{
InitializeComponent();
phoneTask = new PhoneCallTask();
}

PhoneCallTask类包含了两个重要的属性,DisplayName, PhoneNumber,以及一个Show方法,Show方法会打开手机自带的打电话程序,用户可以通过该那个程序拨打电话。 在设计器中双击Button来生成事件处理程序。在事件处理程序中设置DisplayName和PhoneNumber,并且调用Show()方法。请看下面的代码片段。

private void btnCall_Click(object sender, RoutedEventArgs e)
{
phoneTask.DisplayName = "Pavan Pareta";
phoneTask.PhoneNumber = "+911234567890"; // put your desired phone number here
phoneTask.Show();
 
}

现在应用程序已经完成了。当用户点击按钮时,拨号的界面将会出现在界面上,用户只需点击call按钮来打电话即可。请看下面的屏幕截图。

 02.png03.png

这里下载源代码。

总结

简单来说PhoneCallTask会打开手机自带的打电话应用程序。

This page was last modified on 17 July 2013, at 04:51.
143 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×