Searching the Marketplace with the MarketplaceSearchTask

,

The Marketplace search task is used to launch the built-in Marketplace app, which displays the search results for a specified search string.

The MarketplaceSearchTask class has two properties: SearchTerms and ContentType. SearchTerms is a string that contains one or more search terms. ContentType can be set to either MarketplaceContentType.Applications or MarketplaceContentType.Music. If not specified, ContentType defaults to MarketplaceContentType.Applications. The following excerpt demonstrates how to create and launch a MarketplaceSearchTask:

MarketplaceSearchTask task
    = new MarketplaceSearchTask
        {
            ContentType = MarketplaceContentType.Applications,
            SearchTerms = "puzzle"
        };
task.Show();


Tip

The Marketplace app is not shown on the emulator’s App List page. It does, however, exist on the emulator, and it is not necessary to have an unlocked emulator to use it. By calling the Show method on the MarketplaceSearchTask in an app running on the emulator, it allows you to launch the Marketplace app search page and to browse search results using real data.


Sample Overview

Example code for the MarketplaceSearchTask can be found in the MarketplaceViewModel in the downloadable sample code.

The MarketPlaceView has a button that executes an ICommand named SearchCommand in the viewmodel. The searchCommand is instantiated in the MarketplaceViewModel constructor. When executed it creates a new MarketplaceSearchTask, sets its SearchTerms property with the text supplied by a TextBox in the view, sets its ContentType property, and finally calls its Show method, like so:

public MarketplaceViewModel()
{
    searchCommand = new DelegateCommand(
        delegate
            {
                MarketplaceSearchTask task = new MarketplaceSearchTask
                        {
                          /* SearchTerms can't be null or empty,
                           * or else an ArgumentException is thrown. */
                            SearchTerms = string.IsNullOrEmpty(searchTerms)
                                                ? " " : searchTerms
                        };
                if (contentType.HasValue)
                {
                    task.ContentType = contentType.Value;
                }
                task.Show();
            });
// ...
}


Tip

If the MarketplaceSearchTask.SearchTerms property is null or empty, an ArgumentException is raised. To launch the MarketplaceSearchTask without providing search terms, set its SearchTerms property to a string consisting of a single space.


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

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