Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Using Microsoft Advertising Control in Windows Phone apps

From Wiki
Jump to: navigation, search
Featured Article
05 Feb

This article explains how to monetize Windows Phone application using Microsoft Advertising Ad control.

SignpostIcon XAML 40.png
WP Metro Icon WP8.png
SignpostIcon WP7 70px.png
Article Metadata
Code Example
Source file: Media:WP
Tested with
Devices(s): Nokia Lumia 920
Created: pavan.pareta (13 Jan 2012)
Reviewed: SB Dev (15 Sep 2013)
Last edited: hamishwillee (16 Sep 2013)


In mobile application development the term monetization is used to mean the ability to generate revenue thorough your mobile application. It can be from affiliate programs, e- commerce, premium content and advertising.

The market for Windows Phone applications is wide open for developers wanting to monetize their mobile applications. That means endless opportunities for any developer looking to monetize mobile applications. One way of monetization can be advertisement i.e. displaying ads in your apps. In this article we'll see how to achieve such kind of functionality using Microsoft Advertising Ad Rotator Control.


Following are the basic steps to be implemented in a Windows Phone application.

Step-1: Download Microsoft Advertising SDK. (included in newer versions of the WP SDK)

Download Microsoft Advertising SDK for Windows Phone. After downloading the Microsoft Advertising SDK, install it on your development machine.

Step-2: Register mobile App at Microsoft pubCenter.

Register Your Mobile App: Sign up and register your Windows Phone apps using Microsoft pubCenter. Here you can use your live or pubCenter Id.

Ad 001.png

Register your first application and create an ad unit (optional).

Ad 002.png

Enter required information to register your application.

Enter application name:

Device type:

Ad unit name:

Ad unit size:

Select Ad category:

Excluded url:

Ad 003.png

Step-3: Creating the Windows Phone application

1) Create a Windows Phone Application project

Wp Ad 001.png

2) Right click on project in solution explorer panel and click on Add Reference dialog box, click the Browse tab. Navigate to the location where you installed the Microsoft.Advertising.Mobile.UI.dll previously. Click the Microsoft.Advertising.Mobile.UI.dll to select it, and click OK.

Wp Ad 002.png

Wp Ad 003.png

3) Now configure Application Id and Ad Unit Id properties in the Ad Control. Here is two ways to add “Ad Control” in the application using XAML and C# code behind.

Using XAML Drag and drop the Ad Control to Windows Phone xaml page and configure Application Id and Ad Unit Id properties in xaml. See below code snippet:

<my:AdControl Foreground="Red" AdUnitId="AdUnitId" ApplicationId="AppId" Height="80" HorizontalAlignment="Left" Margin="0,6,0,0" Name="adControl1" VerticalAlignment="Top" Width="480" IsAutoRefreshEnabled="True" />

Wp Ad 004.png

Using (C#) code behind Double click on the Windows Phone7 Page, it will automatically open the code behind of a page. And using the AdControl API which is a managed api. Include the Microsoft.Advertising.Mobile.UI namespace in the project. And create an instance of the AdControl Class and set the properties of the AdControl class instance or you can directly pass it to AdControl constructor. See below code snippet:

private const string APPLICATION_ID = "";
private const string AD_UNIT_ID = "";
private AdControl adControl;
// Constructor
public MainPage()
this.Loaded += new RoutedEventHandler(MainPage_Loaded);
this.Unloaded += new RoutedEventHandler(MainPage_Unloaded);
void MainPage_Loaded(object sender, RoutedEventArgs e)
if (!string.IsNullOrEmpty(APPLICATION_ID) && !string.IsNullOrEmpty(AD_UNIT_ID))
adControl = new AdControl(
// Make the AdControl size large enough that it can contain the image
adControl.Width = 480;
adControl.Height = 80;
adControl.Keywords = "Windows Phone 7, Hotels, Travels, Gold";
MessageBox.Show("To show ads in this application, insert the application ID and an ad unit ID into your code as explained..");
void MainPage_Unloaded(object sender, RoutedEventArgs e)

Run the application by using F5 button, and you will see a sample of Monetization in a Windows Phone Application.

Wp Ad 005.png

Note.pngNote: The Microsoft Ad Control detects when it is being run inside the Emulator. It then won't display any Ads unless the official Test-Values are provided for the Application_Id and AdUnit_Id. Those are: ApplicationId: test_client and AdUnitId: Image480_80

Example source code

This page was last modified on 16 September 2013, at 00:01.
497 page views in the last 30 days.