comentsys.wordpress.com today features a Universal Windows Platform tutorial showing how to create a Contacts App which allows Contacts to be added, viewed, edited or deleted from an in-app Contacts List.
There’s an Item class to store a string Id plus a string to store an Address and DisplayName for a Contact. The Library class has a const for the name of Contacts List, then there’s the ContactStore which is specific to the Application, there’s also a method Scope which returns InputScope based on a given InputScopeNameValue. The Dialog method has a Contact passed in and creates a ContentDialog with a given layout to include the First Name, Last Name and Email Address of a Contact object, it also returns the values that have been entered as a Contact when the Save button is selected.
The GetAsync method uses the ContactStore to get the ContactList for the application with FindContactListsAsync and creates one if it doesn’t exist with CreateContactListAsync, ListContactsAsync gets the a list of Contact from the ContactList via ContactReader with GetContactReader and ContactBatch with ReadBatchAsync. GetContactAsync gets an Contact from the ContactList with the GetContactAsync method. The ListAsync is used to populate the list of Item which is based from a list of Contact from the ListContactsAsync method. The Add method uses Dialog to create a new Contact and writes it to the ContactList with SaveContactAsync, Edit uses Dialog with an existing Contact from the list in the UI to make changes and then save this with SaveContactAsync and Delete will remove an existing Contact from the ContactList with the DeleteContactAsync method.
Behind the Scenes
This example shows how easy it is to integrate with the built-in Contacts functionality of Windows 10 – you always need to provide your own UI to add / edit or view any Contacts but it’s quite straightforward to implement and is very similar to how Appointment works with Calendars. You can set many more properties of a Contact beyond those shown to add items such as multiple Email Address types and Telephone Numbers – it’s a good introduction to how you can integrate contacts functionality into any application.