ScrollViewer 释放时向后滚动

发布于 2024-12-18 22:13:45 字数 981 浏览 0 评论 0原文

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

我还尝试将整个 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>

请帮忙

When I tap and hold and move my list around, it moves, but when I no longer hold, it smoothly scrolls back to beginning of the list. How do I prevent it?

I also tried putting whole ItemsControl inside ScrollViewer - same behavior.

Without ScrollViewer ItemsControl doesn't scroll at all.

I set breakpoints to ManipulationCompleted of ItemsPresenter, ItemsControl and ScrollViewer - in all of them scroll appears in correct position where I left it, but afterwards somewhere it scrolls back.

Here's my xaml markup:

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

Please help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

拥抱影子 2024-12-25 22:13:45

问题是 ScrollViewer 需要一个固定大小的容器来了解它实际上可以滚动的信息。

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

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

The issue is that the ScrollViewer needs a container of a fixed size to know much it can actually scroll.

You'll need to set the height of the ScrollViewer or the grid that contains it for scrollign to work properly.

Without doing this the scrollviewer thinks it can take as much space as it likes. When this is the case it doesn't need to scroll and what you see when manipulating the content directly isn't actually scrolling but just moving the content wihtin the scrollable area.

月下伊人醉 2024-12-25 22:13:45

尝试添加RowDefinitions:

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

    ... 
</Grid>

Try adding RowDefinitions:

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

    ... 
</Grid>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文