【WP7】使用联系人和约会数据

在Windows Phone中提供了对联系人和约会数据的访问,相关的类在 Microsoft.Phone.UserData 命名空间,不过wp7不支持没有提供添加约会的接口,只能读取,添加联系人可以通过 SavePhoneNumberTask 添加,但不能批量添加,下面演示调用联系人和约会数据

1、添加命名空间

        using Microsoft.Phone.UserData; 

2、异步获取联系人数据

       //联系人信息
       Contacts contacts = new Contacts();
       contacts.SearchCompleted += contacts_SearchCompleted;
       //可以匹配联系人,第一个参数为String.Empty时获取所有联系人
       contacts.SearchAsync("王二", FilterKind.DisplayName, null);
        void contacts_SearchCompleted(object sender, ContactsSearchEventArgs e)
        {
            foreach (Contact contact in e.Results)
            {
                //Windows live,outlook..
                Account[] accounts = contact.Accounts.ToArray();
                //地址
                ContactAddress[] addresses = contact.Addresses.ToArray();

                DateTime[] birthdays = contact.Birthdays.ToArray();
                string[] children = contact.Children.ToArray();
                ContactCompanyInformation[] companies = contact.Companies.ToArray();
                CompleteName completename = contact.CompleteName;
                string displayname = contact.DisplayName;
                ContactEmailAddress[] emailaddresses = contact.EmailAddresses.ToArray();
                string[] notes = contact.Notes.ToArray();
                ContactPhoneNumber[] phonenumbers = contact.PhoneNumbers.ToArray();
                string[] significantothers = contact.SignificantOthers.ToArray();
                string[] websites = contact.Websites.ToArray();
            }
        }

3、异步获取约会时间

        //约会信息
        Appointments appointments = new Appointments();
        appointments.SearchCompleted += appointments_SearchCompleted;
        appointments.SearchAsync(new DateTime(2013, 01, 01), DateTime.Now, null);
        void appointments_SearchCompleted(object sender, AppointmentsSearchEventArgs e)
        {
            foreach (Appointment appointment in e.Results)
            {
                //数据源
                Account account = appointment.Account;
                //主题
                string subject = appointment.Subject;
                //详细说明
                string details = appointment.Details;
                //地点
                string location = appointment.Location;
                //组织者
                Attendee attendee = appointment.Organizer;
                //参与者
                Attendee[] attendees = appointment.Attendees.ToArray();
                //状态信息
                AppointmentStatus status = appointment.Status;
                //时间
                DateTime starttime = appointment.StartTime;
                DateTime endtime = appointment.EndTime;
            }
        }

 

posted @ 2013-03-27 23:04  bomo  阅读(419)  评论(0编辑  收藏  举报