The downloadable sample code includes a custom ILicenseService
interface, which contains a single property called Trial
, indicating the trial state of the app. There are two implementations of this interface: one for testing and one for production.
The production implementation named LicensingService
wraps a LicenseInformation
instance, as shown in the following excerpt:
public class LicensingService : ILicensingService
{
public bool Trial
{
get
{
LicenseInformation licenseInformation
= new LicenseInformation();
return licenseInformation.IsTrial();
}
}
}
During development and testing, the LicensingService
class is replaced by a MockLicensingService
class, which allows you to change the value of its Trial
property. See the following excerpt:
public class MockLicensingService : ILicensingService
{
bool trial = true;
public bool Trial
{
get
{
return trial;
}
set
{
trial = value;
}
}
}
The particular implementation that is used depends on the type association within the IoC container. When the project is built using a release configuration, LicensingService
is used; otherwise, the MockLicensingService
is used.
Within the ChatClientView
page is a button whose visibility depends on a viewmodel property called BuyOptionVisible
. See the following excerpt:
bool buyOptionVisible;
public bool BuyOptionVisible
{
get
{
return buyOptionVisible;
}
private set
{
Assign(ref buyOptionVisible, value);
}
}
In the viewmodel constructor, the value of the buyOptionVisible
field is determined using the ILicensingService
, which is resolved via the static Dependency
method called Resolve
:
var licensingService = Dependency.Resolve<ILicensingService>();
buyOptionVisible = licensingService.IsTrial;
An AppBarMenuItem
is bound to the BuyOptionVisible
property, as shown:
<u:AppBar.MenuItems>
<u:AppBarMenuItem Text="Buy"
Command="{Binding BuyCommand}"
Visibility="{Binding BuyOptionVisible,
Converter={StaticResource BooleanToVisibilityConverter}}" />
</u:AppBar.MenuItems>
A value converter is used to convert the Boolean value to a Visibility
enum value.
When the user taps the button, the BuyCommand
is executed. In the next section you see how the BuyCommand
uses an abstracted MarketPlaceDetailTask
to launch the built-in marketplace application on the phone.
3.144.97.204