The KnownContactProperties class is under the Windows.Phone.PhoneContract namespace, but ContactManager.RequestStoreAsync () is under the Windows.ApplicationModel.Contacts namespace. This may be the reason you cannot get phone numbers. The ContactStore.CreateOrOpenAsync method on Windows.Phone.PhoneContract the same as the KnownContactProperties can work well. Below is a completed demo to enter a contact, and then enter a name and phone number.
XAML Code
<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>
Code for
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()); } }
Sunteen Wu - MSFT
source share