【问题标题】:Correct scrolling with ScrollViewer in landscape and portrait modes在横向和纵向模式下使用 ScrollViewer 正确滚动
【发布时间】:2012-04-20 07:21:31
【问题描述】:

我有一个带有如下 PivotItem 的简单 Pivot。

<StackPanel>
   <controls:Pivot x:Name="TopPivot" Title="Daily Comics" ItemsSource="{Binding ComicsListModel}" SelectionChanged="TopPivot_SelectionChanged" Height="762">
            <controls:Pivot.HeaderTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding ComicName}"/>
                </DataTemplate>
            </controls:Pivot.HeaderTemplate>
            <controls:Pivot.ItemTemplate>
                <DataTemplate>
                    <StackPanel>
                        <TextBlock Text="{Binding PubDate}" HorizontalAlignment="Center" VerticalAlignment="Top" />
                        <ScrollViewer VerticalScrollBarVisibility="Auto">
                            <Image x:Name="ComicStrip" Source="{Binding ComicImage}" Stretch="UniformToFill" />
                        </ScrollViewer>
                    </StackPanel>
                </DataTemplate>
            </controls:Pivot.ItemTemplate>
   </controls:Pivot>
</StackPanel>

问题是如果图像(名为“ComicStrip”)不完全可见,我希望它垂直滚动。这适用于纵向模式,但不适用于横向模式。在横向中,图像只能部分滚动,图像的底部将不可见。

当我处于横向模式时,我想我必须告诉 ScrollViewer 它的高度,但我不知道如何以及处理这种用例的最佳做法是什么。不过,这似乎是一个基本用例。

有什么建议吗?

【问题讨论】:

  • 如果将 VerticalScrollBarVisibility 设置为 Visible 而不是 Auto,会发生什么?
  • 嗯 - 行为没有区别。更奇怪的是,我在平移图像时也没有看到滚动条。

标签: windows-phone-7 xaml scrollviewer


【解决方案1】:

我认为这里的问题是使用 StackPanel 作为 Pivot 项目模板!如果您使用 Grid,您应该不会有任何问题。

用这个替换你的 Pivot 项目模板:

<controls:Pivot.ItemTemplate>
    <DataTemplate>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition />
            </Grid.RowDefinitions>
            <TextBlock Text="{Binding PubDate}" />
            <ScrollViewer VerticalScrollBarVisibility="Auto" Grid.Row="1">
                <Image x:Name="ComicStrip" Source="{Binding ComicImage}" Stretch="UniformToFill" />
            </ScrollViewer>
        </Grid>
    </DataTemplate>
</controls:Pivot.ItemTemplate>

【讨论】:

  • 谢谢! StackPanel 绝对是这里的问题。我在 XAML 中也有另一个 StackPanel,它没有包含在我的原始粘贴中,所以我也用 Grid 替换了它,现在可以滚动了!最终版本可以在这里看到:link
  • 我这是根本原因。 stackoverflow.com/questions/802821/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多