Barrrdi
Barrrdi

Reputation: 1161

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

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?

Upvotes: 0

Views: 1130

Answers (1)

snacky
snacky

Reputation: 819

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.

Upvotes: 2

Related Questions