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:
Web—The search query is used to perform a web search.
Local—Geographic 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.
News—The 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();
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.
When the SearchTask.Show
method is called, the built-in Search app is launched (see Figure 14.20).
3.19.64.78