如何写入ContactStore.Contact.Phones?

Ben*_*jol 7 c# windows-phone-8.1 windows-10-mobile uwp

从我的应用程序,我使用StoredContact和创建联系人ContactStore,使用KnwonContactProperties.MobileTelephonevia 设置手机号码GetPropertiesAsync.

这很好,我可以看到People中的手机号码.

但...

如果我尝试访问编程通过接触ContactManager.RequestStoreAsync,我没有看到contact.Phones收集这个电话号码.

有没有办法让数字写入Phones系列?

(相关问题)

Sun*_* Wu 1

KnownContactProperties类位于命名空间下,但ContactManager.RequestStoreAsync ()位于 Windows.ApplicationModel.Contacts 命名空间下。这可能是您无法获取电话号码的原因。与 KnownContactProperties 相同的ContactStore.CreateOrOpenAsync方法可以很好地工作。这是一个完整的演示,用于插入联系人,然后获取联系人的姓名和电话号码。Windows.Phone.PhoneContractWindows.Phone.PhoneContract

XAML代码

<StackPanel>
    <TextBox x:Name="txtName" Header="name" InputScope="NameOrPhoneNumber"/>
    <TextBox x:Name="txtTel" Header="phone number 1" InputScope="ChineseHalfWidth"/>
    <TextBox x:Name="txtTel1" Header="phone number 2" InputScope="TelephoneNumber"/>
    <Button x:Name="btnSave" Content="Save" Click="btnSave_Click"/>
    <Button x:Name="btnGet" Content="GET" Click="btnGet_Click"/> 
</StackPanel>
Run Code Online (Sandbox Code Playgroud)

代码隐藏

 private async void btnSave_Click(object sender, RoutedEventArgs e)
 {
     var name = txtName.Text;
     var tel = txtTel.Text;

     ContactStore contactStore = await ContactStore.CreateOrOpenAsync(ContactStoreSystemAccessMode.ReadWrite, ContactStoreApplicationAccessMode.ReadOnly);
     ContactInformation contactInformation = new ContactInformation();
     contactInformation.DisplayName = name;
     var contactProps = await contactInformation.GetPropertiesAsync();
     contactProps.Add(KnownContactProperties.MobileTelephone, tel);
     StoredContact storedContact = new StoredContact(contactStore, contactInformation);
     await storedContact.SaveAsync();
 }

 private async void btnGet_Click(object sender, RoutedEventArgs e)
 {

     ContactStore contactStore = await ContactStore.CreateOrOpenAsync(ContactStoreSystemAccessMode.ReadWrite, ContactStoreApplicationAccessMode.ReadOnly);
     var result = contactStore.CreateContactQuery();
     var count = await result.GetContactCountAsync();
     var list = await result.GetContactsAsync();
     foreach (var item in list)
     {
         var properties = await item.GetPropertiesAsync();
         System.Diagnostics.Debug.WriteLine(item.DisplayName);                
         System.Diagnostics.Debug.WriteLine(properties[KnownContactProperties.MobileTelephone].ToString());
     }
 }
Run Code Online (Sandbox Code Playgroud)