Using Microsoft Advertising Control in WP7 apps
This article explains how to monetize Windows Phone 7 application using Microsoft Advertising Ad control.
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 7 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 7 application.
Step-1: Download Microsoft Advertising SDK.
Download Microsoft Advertising SDK for Windows Phone. After download 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.
Register your first application and create an ad unit (optional).
Enter required information to register your application.
Enter application name:
Ad unit name:
Ad unit size:
Select Ad category:
Step-3: Creating the Windows Phone application
1) Create a Windows Phone 7 Application project
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.
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 7 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" />
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;
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 Windows Phone 7 Application.
Example source code
- Source code of an example app can be downloaded from here - File:WP AdApp.zip