Windows Phone 7编程学习点滴三——12种启动器和4种选择器
一 启动器
有些启动器,它们无法在模拟器上工作。
快速浏览一下启动器:
EmailComposeTask –允许用户通过邮件账户发送电子邮件。
MarketplaceDetailTask –启动Windows Phone Marketplace,让用户查看某个特定的产品。
MarketplaceHubTask –启动Windows Phone Marketplace,默认情况下允许你显示某一类别的应用程序。
MarketplaceReviewTask –将用户带到Windows Phone Marketplace中当前程序的评论页。
MarketplaceSearchTask –启动Windows Phone Marketplace的搜索结果,此结果来源于用户输入的搜索项(或者是你来制定的)。 MediaPlayerLauncher –启动内置的媒体播放器,并播放你指定的媒体文件。
PhoneCallTask –启动电话程序并显示电话号码和姓名。电话只在用户点击“通话”后才会拨出。
SearchTask – 可以把这个看成是在你的程序中提供Bing搜索功能的途径。
SMSComposeTask –启动信息程序并向用户展示发送信息的功能。你可以指定信息接收人和信息内容,但只能通过用户来发送。
WebBrowserTask –打开网络浏览器,跳转到指定的URL。
打开启动器:调用Show()
(1) SMSComposeTask
1 // 测试1 2 SmsComposeTask sct = new SmsComposeTask(); 3 sct.To = "13380307650"; 4 sct.Body = "短信内容测试:有空请呼我。"; 5 sct.Show();
(2) EmailComposeTask
1 EmailComposeTask ect = new EmailComposeTask(); 2 ect.To = "91program@163.com"; 3 ect.Body = "邮件内容测试。"; 4 ect.Cc = "hopease@msn.com"; 5 ect.Subject = "邮件标题"; 6 ect.Show();
(3) PhoneCallTask
1 PhoneCallTask pct = new PhoneCallTask(); 2 pct.PhoneNumber = "13080307650"; 3 pct.DisplayName = "Leo.Zheng"; 4 pct.Show();
(4) MarketplaceDetailTask
1 MarketplaceDetailTask mdt = new MarketplaceDetailTask(); 2 mdt.ContentType = MarketplaceContentType.Applications; 3 mdt.Show();
(5) MarketplaceHubTask
1 MarketplaceHubTask mht = new MarketplaceHubTask(); 2 mht.ContentType = MarketplaceContentType.Applications; 3 mht.Show();
(6) SearchTask
1 SearchTask st = new SearchTask(); 2 st.SearchQuery = "需要查找的内容"; 3 st.Show();
(7) MarketplaceReviewTask
1 MarketplaceReviewTask mrt = new MarketplaceReviewTask(); 2 mrt.Show();
(8) SaveEmailAddressTask
1 SaveEmailAddressTask seat = new SaveEmailAddressTask(); 2 seat.Email = "hopease@msn.com; 3 seat.Show();
(9) MarketplaceSearchTask
1 MarketplaceSearchTask marketplaceSearchTask = new MarketplaceSearchTask(); 2 marketplaceSearchTask.ContentType = MarketplaceContentType.Music; 3 marketplaceSearchTask.SearchTerms = "I am chinese"; 4 marketplaceSearchTask.Show();
(10) SavePhoneNumberTask
1 SavePhoneNumberTask spnt = new SavePhoneNumberTask(); 2 spnt.PhoneNumber = "13080307650"; 3 spnt.Show();
(11) MediaPlayerLauncher
1 MediaPlayerLauncher mpl = new MediaPlayerLauncher(); 2 mpl.Media = new Uri("荷溏月色.mp3", UriKind.Relative); 3 mpl.Location = MediaLocationType.Install; 4 mpl.Controls = MediaPlaybackControls.Pause | MediaPlaybackControls.Stop; 5 mpl.Show();
(12) WebBrowserTask
1 WebBrowserTask wbt = new WebBrowserTask(); 2 wbt.URL = "http://www.hopease.com"; 3 wbt.Show();
二 选择器
需要引用Microsoft.Phone.Tasks名称空间。
选择器,在用户做出选择后需要创建一个事件处理程序。否则,你将无法捕获他们所选的数据。
以下是四种选择器列表:
CameraCaptureTask – 为用户提供在程序中直接拍照的功能。
EmailAddressChooserTask – 在程序中允许用户从联系人里面选择一个邮件地址。
PhoneNumberChooserTask – 在程序中允许用户从联系人里面选择一个电话号码。
PhotoChooserTask – 在程序中允许用户从设备里选择一张照片。
(1)EmailAddressChooserTask
1 EmailAddressChooserTask eact = new EmailAddressChooserTask(); 2 eact.Completed += new EventHandler<EmailResult>(eact_Completed); 3 eact.Show(); 4 // 5 void eact_Completed(object sender, EmailResult e) 6 { 7 EmailBlock.Text = e.Email; 8 }
(2)CameraCaptureTask
1 CameraCaptureTask cct = new CameraCaptureTask(); 2 cct.Completed += new EventHandler<PhotoResult>(cct_Completed); 3 cct.Show(); 4 // 5 void cct_Completed(object sender, PhotoResult e) 6 { 7 BitmapImage bmp = new BitmapImage(); 8 bmp.SetSource(e.ChosenPhoto); 9 image1.Source = bmp; 10 }
(3)PhoneNumberChooserTask
1 PhoneNumberChooserTask pnct = new PhoneNumberChooserTask(); 2 pnct.Completed += new EventHandler<PhoneNumberResult>(pnct_Completed); 3 pnct.Show(); 4 // 5 void pnct_Completed(object sender, PhoneNumberResult e) 6 { 7 PhoneBlock.Text = e.PhoneNumber; 8 }
(4)PhotoChooserTask
1 PhotoChooserTask pct = new PhotoChooserTask(); 2 pct.Completed += new EventHandler<PhotoResult>(pct_Completed); 3 pct.Show(); 4 // 5 void pct_Completed(object sender, PhotoResult e) 6 { 7 BitmapImage bmp = new BitmapImage(); 8 bmp.SetSource(e.ChosenPhoto); 9 image2.Source = bmp; 10 }