Follow us on X (Twitter)  Like us on Facebook  Connect with us on LinkedIn  Subscribe to our YouTube Channel  Subscribe to our WhatsApp Group

Last two days, we learnt about Alarm and Reminder class present for Windows Phone 7 application development. We came to know about the class structure and demoed the implementation with small application created in step-by-step process. We also learnt about the use of Task while discussing the same.


In this tutorial chapter we will learn more about the tasks present for Mango devices. After reading this part you will be able to understand the different tasks and their uses. Read more to learn about them with visual code snippet and huge screenshots.


Index - Windows Phone 7 (Mango) Tutorial


Know about the Tasks

Before going into depth with the implementation, let us first know about the tasks present inside the SDK. You can find all these tasks in the Microsoft.Phone.Tasks namespace. There are lots of classes available there but we will go with some important and useful classes to give you the demonstration. After that, you will be able to understand and use the other classes too.


Here are some classes present inside the Microsoft.Phone.Tasks namespace those we are going to discuss:


AddressChooserTask Allows an application to launch the Contact application
BingMapsTask Allows an application to launch the Bing Maps
CameraCaptureTask Allows an application to launch the Camera application
EmailAddressChooserTask Allows an application to launch the Contacts application
EmailComposeTask Allows an application to launch the Email application
PhoneCallTask Allows an application to launch the Phone application
PhoneNumberChooserTask Allows an application to launch the Phone Contact application
PhotoChooserTask Allows an application to launch the Photo Chooser application
SearchTask Allows an application to launch the Web Search application
SmsComposeTask Allows an application to launch the Messaging application to compose new SMS
WebBrowserTask Allows an application to launch the Web Browser application


From the above list, you will easily understand the use of those classes. Each task class has a method called "Show()" which is responsible to execute the task in the UI. Let's jump start into the practical implementation of the same which will give you better understandings.


Create the MainPage UI

Let us create the Main page UI first, which will consist of some buttons inside a StackPanel. Each button will represent each task to operate. Attach Click event to those buttons respective to the functionalities.


Here is our code snippet of MainPage.xaml file:


WP7.1 Demo - Task Chooser XAML


If you run this now, it will looks as shown below:


WP7.1 Demo - Task Chooser UI      WP7.1 Demo - Task Chooser UI (scrolled)


We added ScrollViewer to enable the view to scroll in case our application takes more space to host the buttons. Yes, we need it. As shown above we have two images to showcase the scrollable container.


Demo of Address Chooser Task

To demonstrate the example implement the click event of the AddressChooserTask button. Create the instance of the AddressChooserTask class and give a call to the Show() method as shown below:

private void AddressChooserTask_Clicked(object sender, RoutedEventArgs e)
    AddressChooserTask addressChooserTask = new AddressChooserTask();


This will open up the contact details in your Phone device as shown here:


WP7.1 Demo - Address Chooser Application


Demo of Bing Maps Task

If you want to show the Bing map in your UI screen with option to searching a specific area, you can go with the class named BingMapsTask. Set the search term to the location, that you want to search in the map.

private void BingMapsTask_Clicked(object sender, RoutedEventArgs e)
    BingMapsTask bingMapsTask = new BingMapsTask();
    bingMapsTask.SearchTerm = "Pune";


The above code will produce the result shown below:


WP7.1 Demo - Bing Maps Task



Demo of Camera Capture Task

If you want to take a snapshot from your camera, you can use the CameraCaptureTask. This will give you option to take the snap from your camera. Let's look into the following code snippet:

private void CameraCaptureTask_Clicked(object sender, RoutedEventArgs e)
    CameraCaptureTask cameraCaptureTask = new CameraCaptureTask();


The above code will produce the same. As we are running it from emulator, you will see a moving box across the screen edges. Click the Capture button to take the snap.


WP7.1 Demo - Camera Capture Task



Demo of Email Address Chooser Task

Here is the code snippet that we are going to use. This will open up the email address chooser screen in the UI:

private void EmailAddressChooserTask_Clicked(object sender, RoutedEventArgs e)
    EmailAddressChooserTask emailAddressChooserTask = new EmailAddressChooserTask();


Running the same will look as shown earlier for the contact chooser task. Here is the screenshot of it:


WP7.1 Demo - Email Adress Chooser Task



Demo of Email Compose Task

This task will create the email composer UI for you. You can set many options like To, CC, BCC addresses, Subject and Body of the email. The implementation of the code will look as below:

private void EmailComposeTask_Clicked(object sender, RoutedEventArgs e)
    EmailComposeTask emailComposeTask = new EmailComposeTask();
    emailComposeTask.To = "";
    emailComposeTask.Subject = "WP7 Email Composing Demo";
    emailComposeTask.Body = "This is a demo message to showcase Email Composing Task.";


Once we run the code inside a physical device, you will see that the email composer screen popped up in the screen. But as we are running it inside emulator, we don't have email box and hence you will see the screen as shown below:


WP7.1 Demo - Email Compose Task



Demo of Phone Call Task

Want to write an application which will call a number? Then this task will help you a lot. PhoneCallTask accepts DisplayName and PhoneNumber as a property to give a call to that mentioned number.

private void PhoneCallTask_Clicked(object sender, RoutedEventArgs e)
    PhoneCallTask phoneCallTask = new PhoneCallTask();
    phoneCallTask.DisplayName = "Kunal Chowdhury";
    phoneCallTask.PhoneNumber = "88888812913";


The above code will run the task as shown below. The first screenshot shows the number with the display name and asks the user to confirm whether he really wants to call the person. Based on user input, it pops up the second screen where you will see the actual call happening to the person.


WP7.1 Demo - Phone Call Task Main UI      WP7.1 Demo - Phone Call Task Calling UI


There are a no. of options present in that screen to end, hold the call. Try out the other options too.


Demo of Phone Number Chooser Task

This task opens up the contact view and from there you can select the contact that you want to call. The implementation is similar to the other task implementation. Have a look:

private void PhoneNumberChooserTask_Clicked(object sender, RoutedEventArgs e)
    PhoneNumberChooserTask phoneNumberChooserTask = new PhoneNumberChooserTask();


Here comes the screenshot:


WP7.1 Demo - Phone Number Chooser Task



Demo of Photo Chooser Task

Want to launch the photo library of your phone device? Then this task will help you. It also has the option to choose the camera roll to view the photo. Here comes the implementation:

private void PhotoChooserTask_Clicked(object sender, RoutedEventArgs e)
    PhotoChooserTask photoChooserTask = new PhotoChooserTask();
    photoChooserTask.ShowCamera = true;


The above code will launch the photo album in the screen as shown below. Clicking on the album will navigate you to the album page where respective photos for that album are stored. Have a look into the following screenshots:


WP7.1 Demo - Photo Chooser Task - Library      WP7.1 Demo - Photo Chooser Task - Album



Demo of Search Task

If you have a need to search the web for a particular string, this task will be useful. Pass the search query to the task and it will do the rest for you as shown here:

private void SearchTask_Clicked(object sender, RoutedEventArgs e)
    SearchTask searchTask = new SearchTask();
    searchTask.SearchQuery = "Kunal Chowdhury";


Let's see the demo of it. Once the search is finished, it will show the result page shown in the below screenshot:


WP7.1 Demo - Search Task Page      WP7.1 Demo - Search Task Result Page



Demo of Compose Task

ComposeTask enables you to create a SMS message using Windows Phone 7. Set the number in the To field followed by the message as body. Let's see the code snippet:

private void SmsComposeTask_Clicked(object sender, RoutedEventArgs e)
    SmsComposeTask smsComposeTask = new SmsComposeTask();
    smsComposeTask.To = "888888123829";
    smsComposeTask.Body = "Demo SMS to Kunal Chowdhury";


The above code will generate the following SMS window:


WP7.1 Demo - SMS Compose Task


Demo of Web Browser task

This task will allow you to open the browser window which will load the URL mentioned in the Uri property. Take a look into the below code snippet for implementation reference:

private void WebBrowserTask_Clicked(object sender, RoutedEventArgs e)
    WebBrowserTask webBrowserTask = new WebBrowserTask();
    webBrowserTask.Uri = new Uri("", UriKind.Absolute);


This will launch the browser with the mentioned URL as shown below. Here I am pointing to my Blog address.


WP7.1 Demo - Web browser Task


End Note

Hope this was a helpful information shared to you. You learnt about most of the useful tasks already present under the Micorosoft.Phone.Tasks namespace. Some more tasks are present there. You can easily find out them by referring the above implementations.


Don't forget to leave a comment/feedback here. This encourages me to deliver the best quality articles to you. Thank you for your time to read my blog. Visit my Facebook page and click the "Like" button to be updated on latest articles. Don't forget to share the link to your friends.

Have a question? Or, a comment? Let's Discuss it below...


Thank you for visiting our website!

We value your engagement and would love to hear your thoughts. Don't forget to leave a comment below to share your feedback, opinions, or questions.

We believe in fostering an interactive and inclusive community, and your comments play a crucial role in creating that environment.