Search code examples
c#xamlwindows-phone-8.1winrt-xaml-toolkit

Including adunit in TopAppBar


I want to add an adunit to the TopAppBar of the page.

    <Page.TopAppBar>
        <AppBar IsOpen="True">
        <UI:AdControl 
          AutoRefreshIntervalInSeconds="60" 
          ApplicationId="be1500d6-9ca7-4a0b-a479-0db279d71e14" 
          AdUnitId="11191335" 
          HorizontalAlignment="Center" 
          IsAutoRefreshEnabled="True" 
          VerticalAlignment="Top" 
          Width="320"
          Height="50" IsAutoCollapseEnabled="True"
          />
        </AppBar>
    </Page.TopAppBar>

This compiles and runs without error but after adding this to my code, the Frame.Navigate to this page is returning a false value. How to correct it so that Navigation is successful? If this is not the right way then how can I make my ad stay on the top of the page always even on scrolling.


Solution

  • Windows Phone doesn't support a top AppBar. If you want to show your add at the top of the page then put it in a row of a Grid at the top of the page. Put the page content you want to scroll in a second row underneath it. Something like:

    <Grid>
        <Grid.RowDefinitions>
             <RowDefinition Height="50"/>
             <RowDefinition Height="*" />
        </Grid.RowDefinitions>
    
        <UI:AdControl Grid.Row="0" />
        <GridView Grid.Row="1" /> <!-- or whatever else you want for the page content -->
    </Grid>