Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>
like image 266
ellic Avatar asked Nov 18 '25 06:11

ellic


1 Answers

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);
like image 167
Kevin Gosse Avatar answered Nov 21 '25 08:11

Kevin Gosse



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!