The Marketplace detail task is used to launch the built-in Marketplace app, which shows the details page for a product specified by a unique identifier that you provide. If an identifier is not specified, the details page for the current application is shown.
The following code demonstrates how to launch the MarketplaceDetailTask
:
MarketplaceDetailTask task
= new MarketplaceDetailTask
{
ContentIdentifier = "<ID>",
//ContentType = MarketplaceContentType.Applications
};
task.Show();
The MarketplaceDetailTask
has two properties: ContentIdentifier
and ContentType
. The ContentIdentifier
is the unique product identifier for an app. When an application is published on the Windows Phone Marketplace it is assigned a unique identifier, which is located in a ProductID
attribute of the WMAppManifest.xml file. This identifier can be used to launch the MarketplaceDetailsTask
from other apps.
If the ContentIdentifier
is specified, the value must be a valid product identifier. If the identifier has an invalid format, a FormatException
is raised. The identifier format is 32 digits separated by hyphens and enclosed in braces, as shown in the following example:
{45dc3711-8af7-42bf-a749-6c491f2b427f}
As an aside, this format can be achieved using a Guid
, by calling its ToString
method with “B” as the format argument, as shown:
string productId = guid.ToString("B");
Although the ContentIdentifier
is not required to launch the MarketplaceDetailTask
for the current app, it is required to launch the details page for a different app. This value can be read at runtime by retrieving the WMAppManifest.xml file using the Application.GetResourceStream
method, and then by extracting the value using the System.Xml.Linq API, as shown in the following excerpt:
public string GetProductId()
{
Uri uri = new Uri("WMAppManifest.xml", UriKind.Relative);
StreamResourceInfo info
= Application.GetResourceStream(uri);
XElement manifestElement = XElement.Load(info.Stream);
XElement appElement = manifestElement.Element("App");
XAttribute idAttribute
= appElement.Attribute("ProductID");
return idAttribute.Value;
}
Example code for the MarketplaceDetailTask
can be found in the MarketplaceViewModel
in the downloadable sample code. The MarketplaceView
page includes a ListBox
to select content type for the MarketplaceHubTask
and the MarketplaceSearchTask
, both of which are discussed later in this chapter, and buttons for exercising the various tasks (see Figure 14.11).
The viewmodel contains a DetailCommand
defined as follows:
readonly DelegateCommand detailCommand;
public ICommand DetailCommand
{
get
{
return detailCommand;
}
}
The detailCommand
is instantiated in the MarketplaceViewModel
constructor. When executed, the detailCommand
creates a new MarketplaceDetailTask
and calls its Show
method. This behavior is defined in the viewmodel constructor, as shown:
public MarketplaceViewModel()
{
detailCommand = new DelegateCommand(
delegate
{
var task = new MarketplaceDetailTask();
task.Show();
});
// ...
}
The MarketPlaceView
uses a button to execute the DetailCommand
in the viewmodel:
<Button Command="{Binding DetailCommand}"
Content="Marketplace Detail" />
18.117.142.128