wp listbox分页加载

来源:互联网 发布:淘宝流量怎么看 编辑:程序博客网 时间:2024/05/21 21:35

private void InitialControl(ListBox listbox)
        {
            List<ScrollBar> scrollBarList = GetVisualChildCollection<ScrollBar>(listbox);
            foreach (ScrollBar scrollBar in scrollBarList)
            {
                if (scrollBar.Orientation == System.Windows.Controls.Orientation.Horizontal)
                {

                }
                else
                {
                    scrollBar.ValueChanged -= new RoutedPropertyChangedEventHandler<double>(verticalScrollBar_ValueChanged);
                    scrollBar.ValueChanged += new RoutedPropertyChangedEventHandler<double>(verticalScrollBar_ValueChanged);
                }
            }

        }


        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 - 1.0;
                if (value >= max)
                {
                    //读取下一页的数据
                    pageIndex++;
                    BindNews(currentListBox, currentType, 5, pageIndex);   
                }
            }
        }

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

0 0
原创粉丝点击