程序实例说明:
一个调用WP 短信API的小程序,图片如下:
程序如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Tasks;
namespace PhoneApp_SMSSample
{
public partial class MainPage : PhoneApplicationPage
{
PhoneNumberChooserTask myChooser = null;
SmsComposeTask SMS =null;
string phoneNumber = "";
// 构造函数
public MainPage()
{
InitializeComponent();
myChooser = new PhoneNumberChooserTask();
myChooser.Completed += new EventHandler<PhoneNumberResult>(myChooser_Completed);
}
void myChooser_Completed(object sender, PhoneNumberResult e)
{
//选择电话本的操作
if (e.TaskResult == TaskResult.OK)
{
this.SomeBodyFormPhoneBook.Text = e.DisplayName+";";
phoneNumber = e.PhoneNumber;
}
}
private void ToSomeBody_Click(object sender, RoutedEventArgs e)
{
//收件人 调用电话本
myChooser.Show();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
//发送
//发送人和发送内容不可以为空
if (SomeBodyFormPhoneBook.Text == "" || SMSContent.Text == "") {
MessageBox.Show("发送人和发送内容不可以为空!");
return;
}
SMS = new SmsComposeTask();
SMS.To = phoneNumber;
SMS.Body = SMSContent.Text;
SMS.Show();
}
}
}