Windows Adds Unity

Hey all,

Build my game and have it running on my windows phone.

Trying to incorporate the adds into the game (windows seems to allow this)

I am having a problem with the final part.

I have found the MainPage.xaml.cs and at the top I put

using Microsoft.Advertising.Mobile.UI;

I then added inside the MainPage() constructor

          //   ApplicationID = "test_client", AdUnitID = "Image480_80", 

            AdControl adControl = new AdControl("test_client",   // ApplicationID
                                                "Image480_80",   // AdUnitID
                                               true);           // isAutoRefreshEnabled
          //   Make the AdControl size large enough that it can contain the image
            adControl.Width = 640;
            adControl.Height = 100;

            Grid grid = (Grid)this.LayoutRoot.Children[0];
            grid.Children.Add(adControl);

         //    Sample code to localize the ApplicationBar
          //  BuildLocalizedApplicationBar();

When I run the game I get an error saying LayoutRoot is not defined.
So I went into the MainPage.xaml and added this line of code for the grid

However I get an error saying content can only be set onece.

Sounds like its a race condition issue. That code shouldn’t be running in the constructor as the page isn’t ready at that point. You could put it in the OnNavigatedTo method.

But I would recommend you add the ad control as part of the xaml on the page that way you dont need to worry about that.

Here’s a sample of the xaml to put in.

<ads:AdControl x:Name="MSAdControl" xmlns:ads="clr-namespace:Microsoft.Advertising.Mobile.UI;assembly=Microsoft.Advertising.Mobile.UI"  
    Height="80" Width="480"
    ApplicationId="APP_ID_HERE"
    AdUnitId="AD_UNIT_HERE" />