C# Windows Phone列表框轻弹行为

C# Windows Phone列表框轻弹行为,c#,silverlight,xaml,windows-phone,C#,Silverlight,Xaml,Windows Phone,全部 在将列表框滚动到顶部时,如果我仍然按住fingure键,列表框将被压缩一小部分,但在我释放点击时,列表框会像正常情况一样弹回来。有没有办法检测到这种行为 目前,我正在使用此代码捕获滚动事件,但当列表框到达顶部或末端时,值将始终为0或作为列表框的高度,即使我按照上面描述的方式进行操作 void PageLoaded(object sender, RoutedEventArgs e) { List<ScrollBar> scrollBarList = Get

全部

在将列表框滚动到顶部时,如果我仍然按住fingure键,列表框将被压缩一小部分,但在我释放点击时,列表框会像正常情况一样弹回来。有没有办法检测到这种行为

目前,我正在使用此代码捕获滚动事件,但当列表框到达顶部或末端时,值将始终为0或作为列表框的高度,即使我按照上面描述的方式进行操作

void PageLoaded(object sender, RoutedEventArgs e)
    {
        List<ScrollBar> scrollBarList = GetVisualChildCollection<ScrollBar>(listBox1);
        foreach (ScrollBar scrollBar in scrollBarList)
        {
            if (scrollBar.Orientation == System.Windows.Controls.Orientation.Horizontal)
            {
                scrollBar.ValueChanged += new RoutedPropertyChangedEventHandler<double>(horizontalScrollBar_ValueChanged);
            }
            else
            {
                scrollBar.ValueChanged += new RoutedPropertyChangedEventHandler<double>(verticalScrollBar_ValueChanged);
            }
        }      
    }

    private void horizontalScrollBar_ValueChanged(object sender, RoutedEventArgs e)
    { 
    }

    private void verticalScrollBar_ValueChanged(object sender, RoutedEventArgs e)
    {
        ScrollBar scrollBar = (ScrollBar)sender;
        object valueObj = scrollBar.GetValue(ScrollBar.ValueProperty);
        object maxObj = scrollBar.GetValue(ScrollBar.MaximumProperty);
        if (valueObj != null && maxObj !=null)
        {
            double value = (double)valueObj;
            double max = (double)maxObj;

            System.Diagnostics.Debug.WriteLine(value);
            System.Diagnostics.Debug.WriteLine(max);
        }
    }

    void btnDelete_Click(object sender, EventArgs e)
    {
        ((ObservableCollection<String>)listBox1.ItemsSource).Remove("hello1");
        listBox1.ScrollIntoView(listBox1.Items[listBox1.Items.Count()-1]);
    }

    public static List<T> GetVisualChildCollection<T>(object parent) where T : UIElement
    {
        List<T> visualCollection = new List<T>();
        GetVisualChildCollection(parent as DependencyObject, visualCollection);
        return visualCollection;
    }
    private static void GetVisualChildCollection<T>(DependencyObject parent, List<T> visualCollection) where T : UIElement
    {
        int count = VisualTreeHelper.GetChildrenCount(parent);
        for (int i = 0; i < count; i++)
        {
            DependencyObject child = VisualTreeHelper.GetChild(parent, i);
            if (child is T)
            {
                visualCollection.Add(child as T);
            }
            else if (child != null)
            {
                GetVisualChildCollection(child, visualCollection);
            }
        }
    }

这样做的目的是什么?目的是在用户将列表滚动到顶部时向列表中添加一个操作,如果用户触发flick事件,则应用程序将加载一些新内容到列表的顶部。哦,这就是刷新。您应该知道,在windows phone上,pull-to-refresh不是一种标准模式,并且没有任何第一方应用程序实现它。以下是备选方案:可能重复的相关: