包含网格的 ScrollViewer 在松开时会回到顶部 [英] ScrollViewer That Contains a Grid Snaps Back to the Top When Let Go

查看:31
本文介绍了包含网格的 ScrollViewer 在松开时会回到顶部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 ScrollViewer 使其包含的网格可滚动.但是,当我向下滚动后松开时,它会自动滚动回Grid的顶部.

I'm using a ScrollViewer to enable the Grid that it contains to be scrollable. However, when I let go after scrolling down, it will automatically scroll back to the top of the Grid.

<ScrollViewer>

    <Grid ShowGridLines="false" MinHeight="700">
        <Grid.RowDefinitions>
            <RowDefinition Height="1" /> 
            <RowDefinition Height="{Binding Pivot1Rows[0].RowHeight}" />
            <RowDefinition Height="1" />
            <RowDefinition Height="{Binding Pivot1Rows[1].RowHeight}" /> 
            <RowDefinition Height="1" />
            <RowDefinition Height="{Binding Pivot1Rows[2].RowHeight}" />
            <RowDefinition Height="1" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="2*" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>

        <!-- Stackpanels for each row/column combo here -->
     </Grid>

</ScrollViewer>

知道我需要添加/更改什么以确保即使在我放手后也能保持向下滚动到的 Grid 位置吗?

Any idea what I need to add/change to ensure the position within the Grid scrolled down to is maintained even after I let go?

推荐答案

您必须将 ScrollViewer 的高度设置为小于 Grid 的高度.如果 ScrollViewer 比它的孩子大,孩子总是会弹回到原来的位置.

You have to set the height of the ScrollViewer to be less than that of the Grid. If the ScrollViewer is larger than it's child, the child will always bounce back to it's original position.

这篇关于包含网格的 ScrollViewer 在松开时会回到顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆