WP8 ScrollViewer滚动结束

时间:2014-06-02 13:22:39

标签: c# windows-phone-8

有谁能建议我如何确定在Windows Phone 8中滚动浏览的结束? LayoutUpdated事件允许用户确定滚动进行的时间,但没有事件,这将允许确定滚动的结束。

编辑:“滚动结束”这句话有一些误解。当用户滚动到scrollviewer的末尾时,我不需要确定状态。我需要的是确定滚动的结束。它不依赖于已经滚动的scrolviwer的哪个部分。

3 个答案:

答案 0 :(得分:2)

使用ViewChanged属性而不是LayoutUpdated。下面是你如何检测scrollviwer结束

示例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..
        }
    }

希望这有帮助。

答案 1 :(得分:2)

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

答案 2 :(得分:1)

这里有多种选择: 轻弹事件,操纵事件。

检查我的回答here