Microsoft Advertising SDK For Windows Phone 7を使ってみる 〜その2〜

前回は静的にAdControlを組み込みました。
Microsoft Advertising SDK for Windows Phone 7を使ってみる 〜その1〜 - 遅咲きのエンジニア
今回は動的にAdControlを組み込んでみます。

1.まずは新規にプロジェクトを作成します。
2.次は参照にSDKの「 Microsoft.Advertising.Mobile.UI.dll 」を追加します。

3.AdControlをプログラムに組み込んでいきます。まずはAdControlを利用するためにMainPage.csにusingを追加します。
using Microsoft.Advertising.Mobile.UI;
4.MainPageのコンストラクタでAdControlを生成してレイアウトに追加します。
// Constructor
public MainPage()
{
    InitializeComponent();

    // 前回紹介したテスト用のIDを使います(大文字と小文字は区別されるので注意)。
    AdControl adControl = new AdControl("test_client", // ApplicationID
                                        "Image480_80",    // AdUnitID
                                        AdModel.Contextual, // AdModel
                                        true);         // RotationEnabled
    // 画像が収まるように大き目のサイズにします。
    adControl.Width = 480;
    adControl.Height = 80;

    // レイアウトに追加します。
    Grid grid = (Grid)this.LayoutRoot.Children[1];
    grid.Children.Add(adControl);
}
5.実行してみましょう!


ほぼヘルプそのままですが詳細は省いてますので、詳しくはSDKのヘルプを参照してください。