我有一个针对Windows/WP 8.1的通用应用程序项目,我试图让广告在两个平台上运行。 在我的控件的OnApplyTemplate函数中,我使用#ifdef动态创建适用于Windows或WP的AdControl。 代码在Windows上运行良好,在WP上广告也能正常显示;但是当我点击它时,没有任何反应。 我尝试用动态按钮替换代码以确保其他东西没有拦截点击事件,而按钮可以很好地工作。 有什么想法吗?
protected override void OnApplyTemplate()
{
base.OnApplyTemplate();
var baseGrid = (Grid)GetTemplateChild("_BaseGrid");
var bannerGrid = (Grid)GetTemplateChild("_BannerGrid");
#if WINDOWS_APP
bannerGrid.Height = 450;
// Create the ad
var ad = new Microsoft.Advertising.WinRT.UI.AdControl()
{
ApplicationId = "0b7b7910-f56d-477c-b0e9-3def577b6359",
AdUnitId = "10056707",
Height = 90,
Width = 728,
Visibility = AdVisibility,
VerticalAlignment = VerticalAlignment.Top,
HorizontalAlignment = HorizontalAlignment.Center
};
baseGrid.Children.Add(ad);
#else
// Set the margins appropriately for WP
bannerGrid.Margin = new Thickness(0, 55, 0, 50);
/* This works just fine!
var button = new Button()
{
Content = "Try This!",
Height = 50,
Width = 320,
VerticalAlignment = VerticalAlignment.Top,
HorizontalAlignment = HorizontalAlignment.Center
};
button.Click += (object sender, RoutedEventArgs args) =>
{
Nova.Utilities.Logger.Info("User tapped on button.");
};
baseGrid.Children.Add(button);*/
// Create the ads
var ad = new Microsoft.Advertising.Mobile.UI.AdControl("f854ae91-1c0e-469c-8387-6c90ef8fa6a2", "11388154", true)
{
Height = 50,
Width = 320,
Visibility = AdVisibility,
IsEnabled = true,
VerticalAlignment = VerticalAlignment.Top,
HorizontalAlignment = HorizontalAlignment.Center
};
ad.IsEngagedChanged += (object sender, RoutedEventArgs args) =>
{
Nova.Utilities.Logger.Info("User tapped on Ad.");
};
baseGrid.Children.Add(ad);
#endif
}