启动器和选择器学习-----(7)选择器之联系人信息保存
namespace Microsoft.Phone.Tasks { public sealed class SaveContactTask : ChooserBase<savecontactresult> { public string FirstName { get; set; } public string LastName { get; set; } public string MiddleName { get; set; } public string Nickname { get; set; } public string Suffix { get; set; } public string Company { get; set; } public string Title { get; set; } public string MobilePhone { get; set; } public string HomePhone { get; set; } public string WorkPhone { get; set; } public string PersonalEmail { get; set; } public string WorkEmail { get; set; } public string OtherEmail { get; set; } public string HomeAddressStreet { get; set; } public string HomeAddressCity { get; set; } public string HomeAddressState { get; set; } public string HomeAddressZipCode { get; set; } public string HomeAddressCountry { get; set; } public string WorkAddressStreet { get; set; } public string WorkAddressCity { get; set; } public string WorkAddressState { get; set; } public string WorkAddressZipCode { get; set; } public string WorkAddressCountry { get; set; } public string Website { get; set; } public string Notes { get; set; } public string JobTitle { get; set; } public override void Show(); } }
1.创建选择器并添加选择器操作完成事件(Completed)
SaveContactTask _SaveContact = new SaveContactTask(); _SaveContact.Completed += new EventHandler<SaveContactResult>(SaveContactCompleted);
2.为选择器赋值(联系人信息)并调用选择器
_SaveContact.FirstName = "张三"; _SaveContact.MobilePhone = "15812345678"; _SaveContact.WorkEmail = "huqg@founder.com"; _SaveContact.Show();
3.选择器操作完成事件
void SaveContactCompleted(object sender, SaveContactResult e) { string nNotifyMessage = string.Empty; switch (e.TaskResult) { case TaskResult.OK: nNotifyMessage = "保存联系人成功!"; break; case TaskResult.Cancel: nNotifyMessage = "用户取消了操作!"; break; case TaskResult.None: nNotifyMessage = "联系人未被保存!"; break; } if (_PageModel != null) _PageModel.SystemTrayNotify(nNotifyMessage); else MessageBox.Show(nNotifyMessage); }