【问题标题】:ScrollViewer scrolls back when releasedScrollViewer 释放时回滚
【发布时间】:2011-11-30 13:06:10
【问题描述】:

当我点击并按住并移动我的列表时,它会移动,但当我不再按住时,它会平滑地滚动回列表的开头。如何预防?

我还尝试将整个 ItemsControl 放入 ScrollViewer - 相同的行为。

如果没有 ScrollViewer,ItemsControl 根本不会滚动。

我为 ItemsPresenter、ItemsControl 和 ScrollViewer 的 ManipulationCompleted 设置了断点 - 在所有这些中,滚动出现在我离开它的正确位置,但之后它会在某个地方滚动回来。

这是我的 xaml 标记:

<Grid x:Name="LayoutRoot">
    <ItemsControl Name="lbDeployments" 
                    ItemsSource="{Binding Path=Deployments}"
                    ItemTemplate="{StaticResource DeploymentItem}" >
        <ItemsControl.Template>
            <ControlTemplate TargetType="ItemsControl">
                <Grid>
                    <ScrollViewer>                    
                        <ItemsPresenter />
                    </ScrollViewer>
                </Grid>
            </ControlTemplate>
        </ItemsControl.Template>
    </ItemsControl>

</Grid>

请帮忙

【问题讨论】:

  • 将 Grid 放入 ScrollViewer 也没有帮助
  • ItemsControl with ScrollViewer is not virtualizing => 可能导致性能不佳...

标签: silverlight xaml windows-phone-7 itemscontrol scrollviewer


【解决方案1】:

问题是 ScrollViewer 需要一个固定大小的容器才能知道它实际上可以滚动多少。

您需要设置 ScrollViewer 或包含它的网格的高度,以便 scrollign 正常工作。

如果不这样做,scrollviewer 认为它可以占用尽可能多的空间。在这种情况下,它不需要滚动,并且您在直接操作内容时看到的实际上并不是滚动,而只是在可滚动区域内移动内容。

【讨论】:

  • @Rico 但没有它,它怎么知道它可以占用多少空间?列表框中的可滚动项是真正糟糕的地方。
【解决方案2】:

尝试添加RowDefinitions

<Grid x:Name="LayoutRoot">
    <Grid.RowDefinitions>
        <RowDefinition Height="*" />
    </Grid>

    ... 
</Grid>

【讨论】:

  • 将其设置为 * 无济于事,但固定值有效。谢谢,好像是挖的方向。
  • 父全景控件好像剪掉了
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-11-20
  • 1970-01-01
  • 1970-01-01
  • 2013-12-15
  • 1970-01-01
相关资源
最近更新 更多