简体   繁体   中英

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.

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.

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

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

Check my answer here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM