Windows Phone 7 获取用户通讯录和日程安排信息 下

下面用一个例子来测试一下获取手机用户的通讯录的信息。

MainPage.xaml文件

 

  
  
  
  
  1. <ListBox Name="ContactResultsData" ItemsSource="{Binding}" > 
  2.                 <ListBox.ItemTemplate> 
  3.                     <DataTemplate> 
  4.                         <StackPanel> 
  5.                             <TextBlock  Text="{Binding DisplayName}" /> 
  6.                             <!--电话号码--> 
  7.                             <ListBox ItemsSource="{Binding PhoneNumbers}"> 
  8.                                 <ListBox.ItemTemplate> 
  9.                                     <DataTemplate> 
  10.                                         <StackPanel Orientation="Horizontal"> 
  11.                                             <TextBlock Text="{Binding PhoneNumber}" /> 
  12.                                         </StackPanel> 
  13.                                     </DataTemplate> 
  14.                                 </ListBox.ItemTemplate> 
  15.                             </ListBox> 
  16.                             <!--邮箱--> 
  17.                             <ListBox ItemsSource="{Binding EmailAddresses}"> 
  18.                                 <ListBox.ItemTemplate> 
  19.                                     <DataTemplate> 
  20.                                         <StackPanel Orientation="Horizontal"> 
  21.                                             <TextBlock Text="{Binding EmailAddress}"/> 
  22.                                         </StackPanel> 
  23.                                     </DataTemplate> 
  24.                                 </ListBox.ItemTemplate> 
  25.                             </ListBox> 
  26.                             <!--地址信息--> 
  27.                             <ListBox ItemsSource="{Binding Addresses}"> 
  28.                                 <ListBox.ItemTemplate> 
  29.                                     <DataTemplate> 
  30.                                         <StackPanel Orientation="Horizontal"> 
  31.                                             <StackPanel> 
  32.                                                 <TextBlock Text="{Binding PhysicalAddress.AddressLine1}"/> 
  33.                                                 <TextBlock Text="{Binding PhysicalAddress.City}"/> 
  34.                                             </StackPanel> 
  35.                                         </StackPanel> 
  36.                                     </DataTemplate> 
  37.                                 </ListBox.ItemTemplate> 
  38.                             </ListBox> 
  39.                         </StackPanel>   
  40.                     </DataTemplate> 
  41.                 </ListBox.ItemTemplate> 
  42.             </ListBox> 

MainPage.xaml.cs文件

 

  
  
  
  
  1. using Microsoft.Phone.Controls;  
  2. using Microsoft.Phone.UserData;  
  3.  
  4. namespace contactstest  
  5. {  
  6.     public partial class MainPage : PhoneApplicationPage  
  7.     {  
  8.         private Contacts contacts;  
  9.  
  10.         public MainPage()  
  11.         {  
  12.             InitializeComponent();  
  13.             contacts = new Contacts();  
  14.             contacts.SearchCompleted += contacts_SearchCompleted;  
  15.             contacts.SearchAsync("", FilterKind.DisplayName, "查询联系人");  
  16.         }  
  17.         //通讯录搜索完成事件处理  
  18.         void contacts_SearchCompleted(object sender, ContactsSearchEventArgs e)  
  19.         {  
  20.             ContactResultsData.DataContext = e.Results;  
  21.         }  
  22.     }  

运行的效果:

 

 

 

 

你可能感兴趣的:(windows,phone,7,获取用户通讯录和日程安排信息)