Microsoft Advertising SDK for Windows Phone 7
Microsoft Advertising是微軟的廣告平台跟 Google Advertising的味道很像,現在已經推出Windows Phone 7的SDK,在你的Windows Phone 7程序中加入文字或者横幅廣告就可以賺錢了,詳細可以參考Raj Kapoor - MSFT接著下來我們就來看一下如何在應用程中怎麼加入 Ad Control
2.執行WP7AdsSDK.msi安裝檔
3.開啟vs2010新增一個Windows Phone 7應用程式專案加入Microsoft.Advertising.Mobile.UI.dll,如何把這個dll加入到此專案使用ad Control 有二種方式:
3.1將滑鼠移至Solution Explorer視窗下點選 References 目錄按下滑鼠右鍵在點選Add Reference接著跳出對話方塊視窗選取剛才安裝sdk所產Microsoft.Advertising.Mobile.UI.dll
使用c#程式碼
using Microsoft.Advertising.Mobile.UI;
在 MainPage函式下加入
string applicationId = "test_client";
string adUnitId = "TextAd";
bool isAutoRotation = true;
AdControl ctrl = new AdControl(applicationId, adUnitId, AdModel.Contextual, isAutoRotation);
ctrl.Width = 480;
ctrl.Height = 80;
this.ContentPanel .Children.Add(ctrl);
目前提供測試參數如下:
Ad Type | Ad Model | AdControl Size (W x H) | Test ApplicationId | Test AdUnitId |
Text Ad | Contextual | 480 x 80 | test_client | TextAd |
XXL Image Banner 6:1 | Contextual | 480 x 80 | test_client | Image480_80 |
X-Large Image Banner 6:1 | Contextual | 300 x 50 | test_client | Image300_50 |
使用xaml程式碼
<Grid xmlns:adctl="clr-namespace:Microsoft.Advertising.Mobile.UI;assembly=Microsoft.Advertising.Mobile.UI" Grid.Row="1"> <adctl:AdControl Height="80" Width="480" AdUnitId="Test" ApplicationId="Test" AdModel="Contextual" /> </Grid>
3.2透過toolbox拖拉元件至表單上,首先將滑鼠移到Toolbox按下滑鼠右鍵點選Choose Items..跳出對話視窗按下Browse鍵選取sdk安裝所產生
Microsoft.Advertising.Mobile.UI.dll,選好後就自動鉤取AdControl在按下ok鍵就會在Toolbox視窗產生元件
接下來從Toolbox上拖AdControl放到表單上面,在來到Properties屬性視窗填入ApplicationId及AdUnitId如上面所提的測試值就可以使用了
4.接著來看一下我自行加入的三種ad模式的程式碼看結果如何,加入以下的程式碼至Page1函式InitializeComponent()後
string applicationId = "test_client";
string adUnitId = "TextAd";
bool isAutoRotation = true;
AdControl ctrl = new AdControl(applicationId, adUnitId, AdModel.Contextual, isAutoRotation);
ctrl.Width = 480;
ctrl.Height = 80;
ctrl.Margin = new Thickness(0, 10, 0, 0);
ctrl.VerticalAlignment = System.Windows.VerticalAlignment.Top;
this.ContentPanel .Children.Add(ctrl);
string applicationId1 = "test_client";
string adUnitId1 = "Image480_80";
bool isAutoRotation1 = true;
AdControl ctrl1 = new AdControl(applicationId1, adUnitId1, AdModel.Contextual, isAutoRotation1);
ctrl1.Width = 480;
ctrl1.Height = 80;
ctrl1.Margin = new Thickness(0, 100, 0, 0);
ctrl1.VerticalAlignment = System.Windows.VerticalAlignment.Top;
this.ContentPanel.Children.Add(ctrl1);
string applicationId2 = "test_client";
string adUnitId2 = "Image300_50";
bool isAutoRotation2 = true;
AdControl ctrl2 = new AdControl(applicationId2, adUnitId2, AdModel.Contextual, isAutoRotation2);
ctrl2.Width = 300;
ctrl2.Height = 50;
ctrl2.Margin = new Thickness(0, 190, 0, 0);
ctrl2.VerticalAlignment = System.Windows.VerticalAlignment.Top;
this.ContentPanel.Children.Add(ctrl2);
備註:Sign up and register your mobile application on pubCenter, define your ad unit and select your user targeting categories. Live starting September 29, 2010.