Is there an easy way to position an AdControl inside of a Panorama? Right now, I can only get my AdControl to show if I set up my object tree like so:
Layout Root > Panorama > ...
> AdControl1
That is, with both my Panorama and my AdControl as immediate children of LayoutRoot.
I only want to show my AdControl on the first PanoramaItem, but when I do this, it fail to render:
LayoutRoot > Panorama > PanoramaItem > StackPanel > ListBox
> AdControl
That is, I want my AdControl to be underneath my ListBox, stuck to the bottom of that PanoramaItem only. What am I missing?
EDIT: The XAML, extra PanoramaItems omitted
Working
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<!--Panorama control-->
<controls:Panorama Title="bad religion">
<controls:Panorama.Background>
<ImageBrush ImageSource="PanoramaBackground.png"/>
</controls:Panorama.Background>
<!--Panorama item one-->
<controls:PanoramaItem Header="content">
<!--Double line list with text wrapping-->
<ListBox x:Name="LyricsListBox" Margin="0,0,-12,0" ItemsSource="{Binding Items}" SelectionChanged="LyricsListBox_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="0,0,0,17" Width="432" Height="78">
<TextBlock Text="{Binding LineOne}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
<TextBlock Text="{Binding LineTwo}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextSubtleStyle}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</controls:PanoramaItem>
</controls:Panorama>
<my:AdControl AdUnitId="TextAd" ApplicationId="test_client" Height="80" HorizontalAlignment="Left" Margin="0,720,0,0" Name="adControl1" VerticalAlignment="Top" Width="480" />
</Grid>
Not Working
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<!--Panorama control-->
<controls:Panorama Title="bad religion">
<controls:Panorama.Background>
<ImageBrush ImageSource="PanoramaBackground.png"/>
</controls:Panorama.Background>
<!--Panorama item one-->
<controls:PanoramaItem Header="content">
<StackPanel>
<!--Double line list with text wrapping-->
<ListBox x:Name="LyricsListBox" Margin="0,0,-12,0" ItemsSource="{Binding Items}" SelectionChanged="LyricsListBox_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="0,0,0,17" Width="432" Height="78">
<TextBlock Text="{Binding LineOne}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
<TextBlock Text="{Binding LineTwo}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextSubtleStyle}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<my:AdControl AdUnitId="TextAd" ApplicationId="test_client" Height="80" HorizontalAlignment="Left" Margin="0,720,0,0" Name="adControl1" VerticalAlignment="Top" Width="480" />
</StackPanel>
</controls:PanoramaItem>
</controls:Panorama>
</Grid>
The reason you cannot see the AdControl is due to your Margin settings. You have
Margin="0,720,0,0"
That places the AdControl 720 pixels down from the top of its container, which in this case is the StackPanel, not the LayoutRoot grid.
That means that the AdControl is off screen.
In your sample code you can create a temporary fix by changing the margin to something like.
Margin="0,420,0,0"
but that is not a good long term solution. You should consider docking or using mutiple rows in a grid.
Another consideration, if you are filling the listbox with lyrics. Have you considered using a textblock with TextWrapping enabled?