1

有没有一种简单的方法可以在全景图中定位 AdControl?现在,如果我像这样设置对象树,我只能让我的 AdControl 显示:

Layout Root > Panorama > ...
            > AdControl1

也就是说,我的 Panorama 和 AdControl 都是 LayoutRoot 的直接子级。

我只想在第一个 PanoramaItem 上显示我的 AdControl,但是当我这样做时,它无法呈现:

LayoutRoot > Panorama > PanoramaItem > StackPanel > ListBox
                                                  > AdControl

也就是说,我希望我的 AdControl 位于我的 ListBox 下方,仅粘在该 PanoramaItem 的底部。我错过了什么?

编辑: XAML,省略了额外的 PanoramaItems

在职的

<!--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>

不工作

 <!--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>
4

2 回答 2

2

您看不到 AdControl 的原因是您的 Margin 设置。你有

Margin="0,720,0,0" 

这会将 AdControl 从其容器顶部向下放置 720 像素,在本例中是StackPanel,而不是 LayoutRoot 网格。

这意味着 AdControl 不在屏幕上。

在您的示例代码中,您可以通过将边距更改为类似的东西来创建临时修复。

Margin="0,420,0,0" 

但这不是一个好的长期解决方案。您应该考虑在网格中停靠或使用多行。

另一个考虑因素,如果你用歌词填充列表框。您是否考虑过使用启用了 TextWrapping 的文本块?

于 2011-11-12T07:42:14.447 回答
1

如果ListBox像 Walt Ritscher 所说的那样将广告控件从页面底部推开,则可以选择将其包装在 aDockPanel而不是 aStackPanel中,并将其设置为 true 并将其中元素的LastChildFill顺序倒置(以便ListBox最后并因此填充 DockPanel 的剩余空间,而不是扩展StackPanel以占用其全部请求的大小)。

也就是说,像这样:

<DockPanel LastChildFill="True" ...>
   <my:AdControl/>
   <ListBox/>
</DockPanel>

可能发生这种情况的原因是它ListBox本身的大小以适合内容(并StackPanel允许它成为它希望的任何大小,而不是DockPanel限制它 - 在这种情况下,在 Windows 上你会添加一个ScrollViewer,但我'不确定你会为电话做什么)。

如果是这种情况,那么您应该会看到截断ListBoxAdControl下方。如果不是,是否AdControl在全景图中单独显示,或者ListBox在堆栈面板中显示?

于 2011-11-12T02:26:54.627 回答