Windows Phone 7 電話本相關的操作

來源:互聯網
上載者:User

抽一點時間學習學習 WP7,由於自己的 C# 基礎很差,加上工作的原因,所以學習的進度很慢。

慢就慢吧,慢慢來。呵呵....

這兩個在 WP7 對電話本的編程進行學習,主要是讀取電話本和操作電話。但發現在 WP7 下對電話本的操作太受限制了,不太適應。

以下代碼,主要是讀取電話本,和通過 SaveContactTask 新增電話本。網上說沒有辦法通過代碼實現編輯、刪除等操作,唉...

 以下代碼中,有兩處編譯未通過。雖然不影響功能,但還是想知道為什麼不行,以後有空繼續吧。

#define _SIMPLE_OUTPUT_PB_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.UserData;// using System.dusing Microsoft.Phone.Tasks;namespace PhoneBookOp{    public partial class MainPage : PhoneApplicationPage    {        // 建構函式        public MainPage()        {            InitializeComponent();        }#if (_SIMPLE_OUTPUT_PB_)
// 注意啊,下面兩個函數是不相同的。當時寫的時候沒有注意,大小區別。        void ContactsSearchCompleted(object sender, ContactsSearchEventArgs e)        {            foreach (var varResult in e.Results)            {                System.Diagnostics.Debug.WriteLine("Name: " + varResult.DisplayName + "Phone number: " + varResult.PhoneNumbers.FirstOrDefault());                listBox1.Items.Add(varResult.DisplayName + " " + varResult.PhoneNumbers.FirstOrDefault());            }        }        private void contactsSearchCompleted(object sender, ContactsSearchEventArgs e)        {            foreach (Contact contactResult in e.Results)            {                string name = contactResult.DisplayName;                ContactPhoneNumber phoneNumber = contactResult.PhoneNumbers.FirstOrDefault();                string strPhone = string.Empty;                if (null != phoneNumber)                {                    strPhone = phoneNumber.PhoneNumber;                }                /*ContactAddress address = contactResult.Addresses.FirstOrDefault();                string strAddr = string.Empty;                if (null != address)                {                    strAddr = address.PhysicalAddress.AddressLine1;     // 此行未編譯通過 System.Device 無法被 using                }*/                ContactEmailAddress emailAddress = contactResult.EmailAddresses.FirstOrDefault();                string strEmail = string.Empty;                if (null != emailAddress)                {                    strEmail = emailAddress.EmailAddress;                }                // System.Diagnostics.Debug.WriteLine("Number:" + strPhone + ";Address:" + strAddr + ";EMail:" + strEmail);                System.Diagnostics.Debug.WriteLine("Number:" + strPhone + ";EMail:" + strEmail);            }        }        void saveContactCompleted(object sender, SaveContactResult e)        {            switch (e.TaskResult)            {                case TaskResult.OK:                    break;                case TaskResult.Cancel:                    break;                case TaskResult.None:                    break;                default:                    break;            }        }        private void SearchPhoneBookClick(object sender, RoutedEventArgs e)        {            Contacts GetContacts = new Contacts();            GetContacts.SearchCompleted += new EventHandler<ContactsSearchEventArgs>(ContactsSearchCompleted);            GetContacts.SearchAsync(string.Empty, FilterKind.None, null);        }        private void SearchPhoneBookClick2(object sender, RoutedEventArgs e)        {            Contacts contacts = new Contacts();            contacts.SearchCompleted += new EventHandler<ContactsSearchEventArgs>(contactsSearchCompleted);            contacts.SearchAsync(string.Empty, FilterKind.None, null);        }        private void AddPhoneBook(object sender, RoutedEventArgs e)        {            SaveContactTask saveContact = new SaveContactTask();            saveContact.Completed +=new EventHandler<SaveContactResult>(saveContactCompleted);            saveContact.FirstName = "Leo.Zheng";            saveContact.MobilePhone = "18665881061";            saveContact.HomeAddressStreet = "廣東省深圳市";            saveContact.PersonalEmail = "doves@126.com";            saveContact.Show();        }#else        void objContacts_SearchCompleted(object sender, ContactsSearchEventArgs e)        {            var ContactsData = from m in e.Results                               select new MyContacts                                   {                                       DisplayName = m.DisplayName,                                       PhoneNumber = m.PhoneNumbers.FirstOrDefault()                                   };            var MyContactsList = from contact in ContactsData                                  group contact by contact.DisplayName into c                                  orderby c.Key select new Group<MyContacts>(c.Key,c);       // 此句編譯不通過            listBox1.ItemsSource = ContactsData;        }        public class MyContacts        {            public string DisplayName { get; set; }            public ContactPhoneNumber PhoneNumber { get; set; }        }#endif    }}

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.