How to create Trial mode application with Microsoft ad support?

It provides attractive option when the user can download and try your application before he/she can purchase your app. But just because you provide trial application means you can’t make money doing so. You can display Microsoft ad when the application is deployed as trial app and make money off of advertising. You will be building demo as shown below that displays the ad.


Preparing  your Microsoft Ad control SDK

You can go to and download Ad SDK and sign up for Microsoft advertising.

Preparing for advertising you want to display in Windows Phone app

Once you are registered at Microsoft advertising and installed Microsoft Ad SDK on your machine you will need to login to and create “apps” that will give you Application ID as show in figure below.


Then you would need to create Ad units which will give you Ad Unit ID as show in below figure.


Create Windows Phone with Microsoft Ad SDK in Trial Mode

Add Microsoft Ad SDK assembly

Once you created Windows Phone project you would need to add reference to Microsoft.Advertising.Mobile.UI.dll found in C:\Program Files (x86)\Microsoft Advertising SDK for Windows Phone 7 (64 bit) or C:\Program Files\Microsoft Advertising SDK for Windows Phone 7 (32 bit) as show in below figure.


Add Ad Control to XAML

In XAML, you would need to add two things xml namespace and the ad control as shown below.









   mc:Ignorable=”d” d:DesignWidth=”480″ d:DesignHeight=”768″

   FontFamily=”{StaticResource PhoneFontFamilyNormal}”

   FontSize=”{StaticResource PhoneFontSizeNormal}”

   Foreground=”{StaticResource PhoneForegroundBrush}”

   SupportedOrientations=”Portrait” Orientation=”Portrait” 



    <Grid x:Name=”LayoutRoot” Background=”Transparent”>


        <my:AdControl Height=”80″ HorizontalAlignment=”Left” Margin=”0,688,0,0″ x:Name=”ad” VerticalAlignment=”Top” Width=”480″/>



Add Code to Codebehind

Then in code behind you would need to properly display ad control when your app is in trial mode. In Microsoft.Phone.Marketplace namespace you will find LicenseInformation class that contains IsTrial() method that return true if the current app is in trial mode. If the app is in trial mode simply collapse the control. BY DEFAULT IsTrial() method ALWAYS RETURNS FALSE.

By default your AdControl will be in test mode and before shipping out your application you want to make sure to test AdControl in none test mode by setting AdControl.TestMode to false. Also you would want to set ApplicationId and AdUnitId properties using the values ontained in Microsoft ad center in above steps. See below for the code that shows these explanations.

using Microsoft.Phone.Controls;

using Microsoft.Advertising.Mobile.UI;

using Microsoft.Phone.Marketplace;


namespace HowToCreateTrialAppWithAdSdk


    public partial class MainPage : PhoneApplicationPage


        public MainPage()




            // Ad if trial

            AdControl.TestMode = false;

            ad.ApplicationId = “your app id”;

            ad.AdUnitId = “your ad unit id”;

            ad.Visibility = System.Windows.Visibility.Collapsed;

            if (new LicenseInformation().IsTrial())


                ad.Visibility = System.Windows.Visibility.Visible;






Download Code


In this demo you learn about how to make money while you allow the user to install you app in trial mode and still make money using Microsoft Ad.

About toetapz

Henry Lee is founder of various start-ups and is passionate about the technology. He is also the author of the book Beginning Windows Phone Development 3nd edition from Apress ( He works with various Fortune 500 companies delivering large multi-million dollar projects. He recently formed start-up company called focusing his energy on delivering mobile applications to the consumers. In his spare time, he dedicates his effort to help his .NET community by delivering sessions at the technology events. He enjoys talking with other technologist about current trends in the technology and sharing business insights with fellow colleagues. Often you will find Henry at local cigar bar enjoying a cigar and a drink trying to come up with next big mobile application.
This entry was posted in Windows Phone 7 and tagged , . Bookmark the permalink.

5 Responses to How to create Trial mode application with Microsoft ad support?

  1. am says:


    Thank you for your tutorial. Unfortunately when I test the App (with Ads) the Ad part is only shown for a few milli-seconds and vanishes immediately… (I commented the trial part out). I took your ApplicationId and AdUnitId and I also choose my own (the one I got in the Microsoft PubCenter) in order to test… what am I doing wrong?

    Thank you!

    • toetapz says:

      You are doing nothing wrong. I deleted applicationid and adunitid from my ad center and below ids will not work which is in the downloaded code.

      ad.ApplicationId = “760bcf5d-1c7e-47db-b12d-9b021a8724e2”;
      ad.AdUnitId = “10011959”;

      You would need to go to and create your own

      • am says:


        Thank you for your fast answer. Actually, I registered to the pubcenter and got an ApplicationId and an AdUnitId. But this didn’t work. When I tried

        ad.ApplicationId = “test_client”;
        ad.AdUnitId = “TextAd”;

        this worked… Perhaps, there is something wrong with the AdUnit-Size?

        Thanks, for your help!

      • toetapz says:

        Only thing I could think of is to make sure to set AdControl.TestMode = false;

  2. am says:

    I did that thanks,… I think I’ll write the MS support. Thanks for your help!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s