In this tutorial we are going to see how to make use of the Email Address Chooser task in windows phone application development. In our previous articles we have seen on how to use the Address Chooser task which gets the address of the Selected contact by triggering an event. This task also works in the similar way instead it gets the Email of the selected contact instead of the address. These chooser tasks are used in specific places where normally user need to play around with the contact information. Let us see the steps on how to achieve this task in real time for a Windows phone application. [more]
Open Visual Studio 2010 IDE and create a new Silverlight for Windows Phone project with a valid project name as shown in the screen below. Once the project is created add some controls which are used to trigger the Email Address Chooser Task as shown in the screen below.
Now drag and drop few controls to the screen which is used to trigger event that launches the Email Address Chooser Task. Once we designed the screen with the controls we can see the screen looks like below. We have added a button control to trigger the event and text block to show the Email address of the selected contact.
Now we need to write our code in the button click event to trigger the Email Address Chooser task on the user click to select the contact. To do that just go to the code behind and first add the USING handler code on top with the existing using statements as shown in the code below.
using Microsoft.Phone.Tasks;
Next is to add the below code to the button click event which basically creates an instance of the Email Address Chooser task while the page is loading, on the Email Address chooser task completed we have written a code which basically gets the Email Address/Email ID of the selected contact as shown in the code below.
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Tasks;
namespace F5debugHowto22
{
public partial class MainPage : PhoneApplicationPage
{
EmailAddressChooserTask eaTask;
// Constructor
public MainPage()
{
InitializeComponent();
eaTask = new EmailAddressChooserTask();
eaTask.Completed += new EventHandler<EmailResult>(eaTask_Completed);
}
private void button1_Click(object sender, RoutedEventArgs e)
{
eaTask.Show();
}
void eaTask_Completed(object sender, EmailResult objResult)
{
if (objResult.TaskResult == TaskResult.OK)
{
textBlock1.Text = “Name Selected :- ” + objResult.DisplayName + ” Email Address is :- ” + objResult.Email.ToString();
}
}
}
}
Now we are done with our code, just run the application by pressing F5 directly from the keyboard or we can use the Build and execute the project option from the tool bar to run the application. Once the Build is successful we can see the Windows Phone emulator with the application and the expected outputs as shown in the screens below.
Output Screens:
We can get the email address and use the Email Compose Launcher task to send an email to the selected contacts email id which is pretty much covers most of the requirement when we develop an application with Windows Phone. That’s it from this tutorial on Windows Phone see you all in the next tutorial soon. Mean while Happy Programming!!!
No Comments
I really liked your article post.Thanks Again. Awesome.
Thanks for contributing your important time to post such an interesting & useful collection.It would be knowledgeable & resources are always of great need to everyone. Please keep continue sharing.<a href= http://www.cellbusters.com/zone-detector-the-ultimate-in-cell-phone-detection/>cell phone detector</a>
That is a good tip especially to those new to the blogosphere. Simple but very accurate information� Thanks for sharing this one. A must read article!