Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get scroll event for ScrollViewer on Windows Phone

Question: Get scroll event for ScrollViewer on Windows Phone

I have a scrollviewer like so:

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
    <ScrollViewer x:Name="MyScroller">
        <StackPanel>
            <!-- ... -->
        </StackPanel>
    </ScrollViewer>
</Grid>

I need the event for when the scrolling occurs for MyScroller:

// MyScroller.Scroll += // <-- "Scroll" event does not exist on ScrollViewer
MyScroller.MouseWheel += MyScroller_MouseWheel; // Does not fire on scroll
MyScroller.ManipulationDelta += MyScroller_ManipulationDelta; // Fires for pinch-zoom only
like image 935
Subcreation Avatar asked Mar 10 '11 19:03

Subcreation


2 Answers

MouseMove fires when ScrollViewer is scrolled:

public MainPage()
{
    InitializeComponent();

    MyScroller.MouseMove += MyScroller_MouseMove;
}

void MyScroller_MouseMove(object sender, MouseEventArgs e)
{
    throw new NotImplementedException();// This will fire
}

It isn't intuitive, since it is named as a "mouse" event and there is no mouse on the phone. The touch point does move, however, relative to the ScrollViewer container, which is how it can handle scrolling.

like image 168
Subcreation Avatar answered Nov 24 '22 13:11

Subcreation


It's not that simple, but there's a few scroll detection mechanisms written in this question:

WP7 Auto Grow ListBox upon reaching the last item

Basically take a look at the way OnListVerticalOffsetChanged is called and used.

like image 40
Stuart Avatar answered Nov 24 '22 12:11

Stuart