繁体   English   中英

WP8 ScrollViewer滚动结束

[英]WP8 ScrollViewer scroll ended

谁能建议我如何确定Windows Phone 8中scrollview滚动的结束? LayoutUpdated事件允许您确定何时进行滚动,但没有事件可以确定滚动的结束。

编辑:在短语“滚动结束”中有一些误解。 当用户滚动到scrollviewer的末尾时,我不需要确定状态。 我需要确定滚动的结束。 它不取决于滚动脚本的哪一部分已经滚动。

使用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..
        }
    }

希望这可以帮助。

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

在这里,您有多个选择:轻拂事件,操纵事件。

在这里检查我的答案

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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