簡體   English   中英

檢測用戶何時執行垂直滾動

[英]Detect When User performs Vertical Scroll

我在Windows Phone應用程序屏幕之一中使用“ 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>

試試這個,在列表框的情況下對我有用。

定義以下方法和屬性;

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM