WP8 ScrollViewer滚动结束

本文关键字:结束 滚动 ScrollViewer WP8 | 更新日期: 2023-09-27 18:06:18

有没有人建议我如何确定在windows phone 8中滚动视图的滚动结束?layoutupdate事件允许人们确定滚动何时在进行中,但没有事件允许确定滚动的结束。

编辑:"end of the scrolling"这个短语有一些误解。我不需要确定用户滚动到scrollviewer结束时的状态。我需要确定滚动的结束。它不依赖于scrolviwer的哪个部分已经被滚动。

WP8 ScrollViewer滚动结束

使用ViewChanged属性代替layoutupdate。下面是如何检测scrollviewer

结束的方法样本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>
事件处理程序

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

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

可以检测到滚动结束:

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

这里有多个选项:点击事件,操作事件。

点击这里查看我的答案