WindowsPhone 8持久AdControl

时间:2014-02-20 23:41:16

标签: c# windows-phone-8 advertising

我希望制作一个多页的WindowsPhone 8应用,其底部带有AdControl。现在我感兴趣的是找出是否有可能将AdControl放在一个单独的排序框架中,以便页面导航不会干扰它。基本上我正在尝试将应用ViewPort拆分为两部分:应用和AdControl。

AdControl应始终打开,无需将其添加到不同的页面,并在每次执行导航时刷新它。

可以这样做吗?

1 个答案:

答案 0 :(得分:2)

您可以通过设置PhoneApplicationFrame的样式来完成此操作。在App.xaml中,添加以下资源

<Style x:Key="AdPhoneApplicationFrameStyle" TargetType="phone:PhoneApplicationFrame">
    <Setter Property="IsTabStop" Value="False"/>
    <Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/>
    <Setter Property="FontSize" Value="{StaticResource PhoneFontSizeNormal}"/>
    <Setter Property="FontFamily" Value="{StaticResource PhoneFontFamilyNormal}"/>
    <Setter Property="HorizontalAlignment" Value="Stretch"/>
    <Setter Property="VerticalAlignment" Value="Stretch"/>
    <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
    <Setter Property="VerticalContentAlignment" Value="Stretch"/>
    <Setter Property="Background" Value="Transparent"/>
    <Setter Property="BorderThickness" Value="0"/>
    <Setter Property="BorderBrush" Value="{x:Null}"/>
    <Setter Property="Padding" Value="0"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="phone:PhoneApplicationFrame">
                <Border x:Name="ClientArea" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="*"/>
                                <RowDefinition Height="Auto"/>
                            </Grid.RowDefinitions>
                            <ContentPresenter ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                            <adDuplex:AdControl Grid.Row="1"/>
                    </Grid>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

InitializePhoneApplication内的App.xaml.cs中,在创建RootFrame后添加以下行

RootFrame.Style = (Style)Resources["AdPhoneApplicationFrameStyle"];

如果您想要进行页面转换,请参阅此blog post以获取更多信息。