ScrollViewer That Contains a Grid Snaps Back to the Top When Let Go

社会主义新天地 提交于 2019-12-25 02:43:02

问题


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>

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?


回答1:


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.



来源:https://stackoverflow.com/questions/19825911/scrollviewer-that-contains-a-grid-snaps-back-to-the-top-when-let-go

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!