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.
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.
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.
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.
public partial class MainPage : PhoneApplicationPage
private void button1_Click(object sender, RoutedEventArgs e)
SearchTask st = new SearchTask();
st.SearchQuery = textBox1.Text.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 opened as shown in the screens below.
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!!!