仅在纵向模式下显示AdControl



当手机处于横向模式时,我的应用程序中没有足够的屏幕空间来显示AdControl。我在OnOrientationChanged事件处理程序中使用以下(简化)代码,在进入横向模式时从网格的第1行删除AdControl,并在进入纵向模式时将其添加回:

if (this.Orientation == PageOrientation.LandscapeLeft || 
    this.Orientation == PageOrientation.LandscapeRight) {
    LayoutRoot.Children.Remove(myAdControl);
    LayoutRoot.RowDefinitions.RemoveAt(1);// remove row to make space
} else {
    LayoutRoot.RowDefinitions.Add(adRow);// previously constructed 80 px high RowDefinition
    LayoutRoot.Children.Add(myAdControl);
    Grid.SetRow(myAdControl, 1);
}

这在我的测试中似乎有效,但我在AdControl类的文档中看到,"一旦设置,AdControl的父级就不应该更改。"我在这里所做的会破坏AdControl吗?

这里有一个新的解决方案,当手机方向更改为横向时,广告控件可以保持静止。它使用了一个新的控件,即使在旋转时(横向时向左或向右),也能将广告控件保持在"底部"。

10秒的概述是创建一个网格布局,并将AdControl移动到适用于方向的行/列组合中。博客中有所有的细节。

最新更新