用户执行垂直滚动时检测

时间:2014-01-02 16:37:32

标签: c# .net windows-phone-7 scroll

我在我的一个Windows手机应用程序屏幕中使用Pivot,我想检测用户是否正在执行垂直滚动。 我注意到没有用于检测它的内置事件,我还注意到ScrollViewer,Grid etc没有Scroll属性。 我想知道是否可以检测到垂直滚动。如果有人能指出我的解决方案,我将不胜感激。提前谢谢!

<ScrollViewer Name="mailSV">
    <controls:Pivot Name="mailPivot" Title="EyeLight">
        <!--Pivot item one-->
        <controls:PivotItem Name="GmailPivot" Header="Gmail">
            <!--Double line list with text wrapping-->
            <Button Name="Gmail" Tap="mailSingleTap" DoubleTap="listenMode" FontSize="120" Foreground="Black">
                <Button.Background>
                    <ImageBrush ImageSource="/ScrollingApp;component/Images/Gmail-icon.png" Stretch="Uniform" />
                </Button.Background>
            </Button>
        </controls:PivotItem>

            <!--Pivot item two-->
        <controls:PivotItem Name="YahooPivot" Header="Yahoo">
            <!--Triple line list no text wrapping-->
            <Button Name="Yahoo" FontSize="120" Tap="mailSingleTap" DoubleTap="listenMode" Foreground="Black">
                <Button.Background>
                    <ImageBrush ImageSource="/ScrollingApp;component/Images/yahoo2.jpeg" Stretch="Uniform" />
                </Button.Background>
            </Button>
        </controls:PivotItem>
    </controls:Pivot>
</ScrollViewer>

1 个答案:

答案 0 :(得分:1)

试试这个,如果是列表框,它对我有用。

定义以下方法和属性;

ScrollViewer scrollViewer;

 private static void OnListVerticalOffsetChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
            {
                //Create an object of the same class(page).      
                MyPage page = obj as MyPage ;

                ScrollViewer viewer = page.scrollViewer;

                //Checks if the Scroll has reached the last item based on the ScrollableHeight
                bool atBottom = viewer.VerticalOffset >= viewer.ScrollableHeight;

                if (atBottom)
                {
                    //Type your Code here after checking the vertical scroll.               
                }
            }

现在使用以下代码通过使用上述方法获取ListVerticalOffset的值。

public readonly DependencyProperty ListVerticalOffsetProperty = DependencyProperty.Register("ListVerticalOffset", typeof(double), typeof(ImageSearch),
                new PropertyMetadata(new PropertyChangedCallback(OnListVerticalOffsetChanged)));

现在将此属性绑定到ListBox的Loaded事件上的当前实例。

void listBox_Loaded(object sender, RoutedEventArgs e)
        {

            FrameworkElement element = (FrameworkElement)sender;
            element.Loaded -= LstImage_Loaded;
            scrollViewer = FindChildOfType<ScrollViewer>(element);
            if (scrollViewer == null)
            {
                throw new InvalidOperationException("ScrollViewer not found.");
            }

            Binding binding = new Binding();
            binding.Source = scrollViewer;
            binding.Path = new PropertyPath("VerticalOffset");
            binding.Mode = BindingMode.OneWay;
            this.SetBinding(ListVerticalOffsetProperty, binding);
        }