0

Can anyone suggest how I can determine the end of scrollview's scrolling in windows phone 8? LayoutUpdated event allows one to determine when scrolling is in progress, but there is no event, which will allow to determine the end of the scroll.

Edit: There is some misunderstanding in the phrase "end of the scrolling". I do not need to determine the state when user scrolls to the end of scrollviewer. What I need is to determine the end of scrolling. It does not depend on what part of scrolviwer has been already scrolled.

Vahagn Nahapetyan
  • 1,337
  • 13
  • 22
  • Have you checked this link : http://blogs.msdn.com/b/slmperf/archive/2011/06/30/windows-phone-mango-change-listbox-how-to-detect-compression-end-of-scroll-states.aspx ? – Shmwel Jun 02 '14 at 13:25
  • No, I hadn`t, but according to users` comments the mechanism described in the link is designed for listbox and has some problems with ScrollViwer. Also the used version of WP is 7. – Vahagn Nahapetyan Jun 02 '14 at 13:34

3 Answers3

2

Use ViewChanged property instead of LayoutUpdated. below is how you can detect the end of scrollviwer

sample xaml

<ScrollViewer Name="scrollViewer" Height="200" ViewChanged="scrollViewer_ViewChanged">
        <StackPanel Name="canContentContaner" Height="auto" Background="Orange"                           Orientation="Vertical">
            <Button Height="60" Content="TEst button"></Button>
            <Button Height="60" Content="TEst button"></Button>
            <Button Height="60" Content="TEst button"></Button>
            <Button Height="60" Content="TEst button"></Button>
            <Button Height="60" Content="TEst button"></Button>
            <Button Height="60" Content="TEst button"></Button>
        </StackPanel>
    </ScrollViewer>

Event handler

 private async void scrollViewer_ViewChanged(object sender, ScrollViewerViewChangedEventArgs e)
    {
        if (e.IsIntermediate==false) //&& scrollViewer.VerticalOffset >= canContentContaner.ActualHeight - scrollViewer.ActualHeight)
        {
           //The scrolling has ended..
        }
    }

Hope this helps.

Muhammad Saifullah
  • 4,292
  • 1
  • 29
  • 59
2

Found solution in http://blogs.msdn.com/b/ptorr/archive/2010/07/23/how-to-detect-when-a-list-is-scrolling-or-not.aspx

FrameworkElement element = VisualTreeHelper.GetChild(viewer, 0) as FrameworkElement; 
if (element != null) 
{ 
  VisualStateGroup group = FindVisualState(element, "ScrollStates"); 
  if (group != null) 
  { 
    group.CurrentStateChanging += (s, args) => PageTitle.Text = args.NewState.Name; 
  } 
} 

VisualStateGroup FindVisualState(FrameworkElement element, string name) 
{ 
  if (element == null) 
   return null;

IList groups = VisualStateManager.GetVisualStateGroups(element); 
foreach (VisualStateGroup group in groups) 
if (group.Name == name) 
  return group;

return null; 
}

Scroll end can be detected:

group.CurrentStateChanging += (s, args) =>
                    {
                        if (args.OldState.Name == "Scrolling" && args.NewState.Name == "NotScrolling")
                        {

                            //Scroll end
                        }
                    };
Vahagn Nahapetyan
  • 1,337
  • 13
  • 22
1

Here you have multiple options : Flick Events, Manipulation events.

Check my answer here

Community
  • 1
  • 1
vITs
  • 1,651
  • 12
  • 30
  • Sorry, I guess I was not clear in my question. I do not need to implement lazy load mechanism or determine the state when user scrolls to the end of the scrollviewer. What I need is to determine when scrolling ends. Scrolling can be finished in any position of scrollbar. – Vahagn Nahapetyan Jun 02 '14 at 13:57
  • Ohh..In this case you can use Flick events...you can get offset of scroll position in its handler and by using VerticalVelocity value you can tackle the position – vITs Jun 02 '14 at 13:59
  • I tried to do so, but the thing is, that you can scroll scrollviewer without stopping and by making dozens of gestures. The event what I used was "MouseLeave". – Vahagn Nahapetyan Jun 02 '14 at 14:12
  • No need of MouseLeave.Check these [forum1](http://stackoverflow.com/questions/17148985/implement-flick-gesture-via-gestureservice-from-windows-phone-8) and [forum2](http://stackoverflow.com/questions/21399514/implement-swipe-event-on-wp8).Your idea related to Flick events will get cleared. – vITs Jun 03 '14 at 05:10