Search code examples
windows-phone-7scrollviewer

How to control the scroll-position of a scrollviewer in windows phone


I am using a scrollviewer to show contents, and added a "DoubleTap" event to the scrollviewer. In the doubleTap event I want to make the scrollviewer automatically scroll up to the top of the scrollviewer, but I can't find any property to control the scrollviewer. any thoughts?

Thanks in advance.

            <Grid x:Name="ContentPanel" Grid.Row="1" Margin="0,0,0,0">
                <ScrollViewer x:Name="scrollViewer2" Height="auto">
                    <toolkit:GestureService.GestureListener>
                        <toolkit:GestureListener  DoubleTap="GestureListener_DoubleTap"/>
                    </toolkit:GestureService.GestureListener>
                    <StackPanel x:Name="stackPanel2" Height="auto">
                         <!--contents-->
                    </StackPanel>
                </ScrollViewer>
            </Grid>

Solution

  • You don't have properties, but you have two methods for this: ScrollToVerticalOffset (to scroll vertically) and ScrollToHorizontalOffset (to scroll horizontally).

    So in your case, this code should do the trick:

    this.scrollViewer2.ScrollToVerticalOffset(0);