Vahagn Nahapetyan
Vahagn Nahapetyan

Reputation: 1357

WP8 ScrollViewer scroll ended

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.

Upvotes: 0

Views: 1065

Answers (3)

Vahagn Nahapetyan
Vahagn Nahapetyan

Reputation: 1357

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
                        }
                    };

Upvotes: 2

Muhammad Saifullah
Muhammad Saifullah

Reputation: 4292

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.

Upvotes: 2

vITs
vITs

Reputation: 1560

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

Check my answer here

Upvotes: 1

Related Questions