Matthias Shapiro

I need fewer hobbies

Using an AdControl in a Trial App (Windows Phone)

I had to search around for this information so I thought it would be nice to have it somewhere handy. Here’s the scenario: You want to put ads into your Windows Phone app, but only when it is in trial mode.

To start:

  • Download the Microsoft Ads SDK
  • Sign into the Microsoft pubCenter and add an ad and an application to your account. You will get an ad id and an application id that we’ll use below to display the ads.

Add Permissions for the AdControl

We need the following permissions set in the WMAppManifest.xml file to get the AdControl to work.


Add structure for your AdControl

I decided that the best way to do this was to create a Grid layout with 2 rows. The top row is for all the important stuff in my app and the bottom row is holding my AdControl. The XAML looks something like this:

<Grid x:Name="LayoutRoot" >
        <RowDefinition Height="*"/>
        <RowDefinition Height="Auto"/>
    <Grid x:Name="MyContent">
        <!-- all my UI goes here -->
    <Border x:Name="AdControlHolder" Grid.Row="1">

Add logic to include the AdControl if we are in trial mode

If I don’t place anything in my Border control, it will be completely invisible. So what we’re going to do is:

  1. Check to see if our app is in a trial mode
  2. If it is, add the AdControl. Otherwise do nothing.

The only problem with this is that it can be difficult to test. For one thing, the AdControl requires some custom parameters to run in a test environment. Additionally, we can’t set the app to “trial mode” in the test environment, so we have to simulate it. I’ve tried to take all this and encapsulate it in a block of code.

LicenseInformation info = new LicenseInformation();
if (true) 
if ( info.IsTrial() ) 
    // running in trial mode
    AdControl ac = new AdControl();
    ac.AdUnitId = "Image480_80";
    // or for text ads
    //ac.AdUnitId = "TextAd";
    // or for smaller ads
    //ac.AdUnitId = "Image300_50";
    ac.ApplicationId = "test_client";
ac.AdUnitId = "000000"; // insert your AdUnitId from the pubCenter site
    // add your ApplicationId from the pubCenter
    ac.ApplicationId = "12345678-1234-1234-1234-123456789012";
    ac.Width = 480;
    ac.Height = 80;
    AdControlHolder.Child = ac;

And that should be good to get started!

This entry was posted in Windows Phone and tagged , , . Bookmark the permalink.