Introduction:
In this article we are going to see how to work with inbuilt contacts data and use it across our requirement to manipulate the data. Windows Phone 7.1 provides a read only access to the data available locally across the device. We can query the data and select the users based on the search filters and also we can do multiple manipulations in order to perform some operation with the user contact information’s. [more]
Let us see the step by step process on how to use the contacts for querying the data. To launch the contacts we need to use the AddressChooserTask which is used to select the contacts. The queried result can be collected in the AddressResult object and can be used to list it as per the requirement. Let us start with creating a new application and start using the AddressChooserTask.
Steps:
Open Visual Studio 2010 and create a new Silverlight for Windows Phone 7 project and provide a valid project name as shown in the screen below.
Now we will add a button which triggers an event to query the data and get the contacts in a list. Add the below XAML code, or we can directly drag and drop the controls as shown in the screen below.
XAML Code:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Now we will add some code to the code behind page for querying the data from the contacts database. To do that go to the button click event and write the code below. Basically the Windows Phone 7 Emulator has some default contacts which can be tested by pulling to the list in this article. We need to add the namespace in order to access the data.
|
|
Now in the button click event add the below code. From the code we can see the Contact class been used to query the details. Here we will be using the SearchAsyc method to do the search with the object and provide the result set to the list as shown in the code below.
C# Code:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
In the above code if we see we are querying the contacts class object and bind it to the list box using the data context and do some small user information with the message. In the SearchAsync method we provide different filters that can be used to access the data. Below is the list of filters that can be provided based on the requirement.
- Search All Contacts – SearchAsync(String.Empty, FilterKind.None, null)
- Get Pinned Contacts – SearchAsync(String.Empty, FilterKind.PinnedToStart, null)
- Search by Display Name – SearchAsync(“Karthik”, FilterKind.DisplayName, null)
- Search by Email ID – SearchAsync(“Karthik@f5debug.net”, FilterKind.EmailAddress, null)
- Search by Phone No – SearchAsync(“123-456-7890″, FilterKind.PhoneNumber, null)
Now we are done with the application just to build and execute the application to check in the emulator press F5 or click on Build and execute the solution. We can see the end result by pressing the button once the application is loaded as shown in the screen below.
The list of contacts which are shown in the above screen is the default contacts available with the Emulator for testing purposes. We can use these contacts to do the testing and add or delete it based on the requirement.
Conclusion:
So in this article we have seen how to use the contacts data search using the AddressChoosertask and list the data to the list view.
No Comments
Wow, that�s what I was searching for, what a stuff! present here at this web site, thanks admin of this web page.