Searching the Web with the SearchTask

,

The Search task is used to launch the built-in Search application and performs a search for the specified search string. The Search application presents search results for the following three categories:

Image WebThe search query is used to perform a web search.

Image LocalGeographic location is used to provide search results that are relevant to the user’s location. For example, searching for the term restaurant presents a map with the location of nearby restaurants.

Image NewsThe search query is used to perform a search of various news-related websites and blogs.

The SearchTask class has a single string property called SearchQuery.


Note

If the SearchQuery property is null or empty, calling the SearchTask.Show method has no effect.


The following excerpt demonstrates how to initiate a SearchTask:

SearchTask searchTask = new SearchTask { SearchQuery = "restaurant" };
searchTask.Show();

Sample Overview

Example code for the SearchTask can be found in the SearchViewModel in the downloadable sample code.

The SearchView allows the user to populate a TextBox with a search query. The TextBox has a two-way data binding to the viewmodel’s SearchQuery property.

A button is used to execute an ICommand named SearchCommand, which initiates the SearchTask.

The searchCommand field is instantiated in the SearchViewModel constructor. When executed, the searchCommand creates a new SearchTask and sets its SearchQuery property to the text supplied by a TextBox in the view, as shown in the following excerpt:

public SearchViewModel()
{
    searchCommand = new DelegateCommand(
        delegate
            {
                SearchTask searchTask = new SearchTask
                                            {
                                                SearchQuery = searchQuery
                                            };
                searchTask.Show();
            });
}

Figure 14.19 shows the custom SearchView page.

Image

FIGURE 14.19 The sample search page allows the user to enter a search query.

When the SearchTask.Show method is called, the built-in Search app is launched (see Figure 14.20).

Image

FIGURE 14.20 The built-in Search app.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.146.105.194