Floating FB popout byF5debug

101 How to on Windows Phone – How to #7 – Play with Search Task in Windows Phone

 

In this short tutorial we are going to see how to use the Search task available in Windows Phone development. Search Task is one of the type of Launcher available with the Windows Phone SDK, with Search Task we can provide a selected query to be searched over the web and provide the result with the web search application. We can use this task in our application development, providing the user to search for some specified result or a query with in the application or to search over the web. By using the available Launchers provided by Windows Phone, we can make a unique user experience to the end users.       [more]

Let us see the a demo on how to use the search task in our application step by step.

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 Search Task with a provided query to search the web.

clip_image002

Now let us add some controls to have a unique design, where we will add a button and a text box as shown in the screen below. Text box is used to enter the query which is required to be searched over the web on the button click event.

clip_image0044

We have done with the UI design, now let us add code behind to achieve our requirement to handle the Search Task effectively. First let us add the assembly reference as a namespace (Microsoft.Phone.Task) in the using statement, which is required to make use of the search task as shown in the code below.

using Microsoft.Phone.Tasks;

Now we need to create an instance of the Search Launcher task and pass the query which the user inputs as shown in the code below. Basically we are trying to pass the value from the text box to the web browser using the search task which triggers the browser with the query specified by the end user as shown below.

C# 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 F5debugHowto7
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            SearchTask st = new SearchTask();

            st.SearchQuery = textBox1.Text.ToString();
            st.Show();
        }
    }
}

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 opened as shown in the screens below.

clip_image006
Output:
clip_image008
clip_image010

So in this short tutorial, we have see how to use the search task effectively to search for some specified string or a query over the web with the standard way provided by the Windows Phone launchers to have unique experience across the applications and its usage. See you in the next tutorial until then Happy Programming!!!

About Author: Karthikeyan Anbarasan, Microsoft MVP (Most Valuable Professional) in ASP.NET/IIS Architecture. He is the Founder and Chief Editor of the www.f5debug.net website and has authored books on Windows Phone and Business Intelligence(SSIS). He is also a Passionate Speaker and a Blogger on Microsoft Technologies.

You can Join Me On: Facebook, Twitter, Google Plus, LinkedIn

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

Recent Posts

Random Posts

Most Viewed

URL Shortner

Create your own short urls!!!

Site Counter

free counters

Disclaimer

This is a personal weblog. The opinions expressed here represent my own and not those of my employer. For accuracy and official reference refer to MSDN/ TechNet. I have documented my personal experience on this blog.

Protected by Copyscape Web Plagiarism Finder

Site Meter