分頁方法:
using System;using System.Net;using System.Windows;using System.Windows.Controls;using System.Windows.Documents;using System.Windows.Ink;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Animation;using System.Windows.Shapes;using System.Windows.Controls.Primitives;using System.Collections.Generic;namespace MicroBlogForWP7.Classes{ public class UtilPager { #region 分頁調用方法 /// <summary> /// 分頁 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public 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) { //讀取下一頁的資料 //GetPublicMicroBlog(); } } } public static List<T> GetVisualChildCollection<T>(object parent) where T : UIElement { List<T> visualCollection = new List<T>(); GetVisualChildCollection(parent as DependencyObject, visualCollection); return visualCollection; } public 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); } } } #endregion /// <summary> ///擷取控制項的子控制項 /// </summary> /// <typeparam name="T">子控制項類</typeparam> /// <param name="root">父控制項</param> /// <returns></returns> public static T FindChildOfType<T>(DependencyObject root) where T : class { var queue = new Queue<DependencyObject>(); queue.Enqueue(root); while (queue.Count > 0) { DependencyObject current = queue.Dequeue(); for (int i = VisualTreeHelper.GetChildrenCount(current) - 1; 0 <= i; i--) { var child = VisualTreeHelper.GetChild(current, i); var typedChild = child as T; if (typedChild != null) { return typedChild; } queue.Enqueue(child); } } return null; } /// <summary> /// 高敏感翻頁 /// </summary> public static bool HightDragSensitivity { get { return false; } } }}
調用:
List<ScrollBar> scrollBarList = GetVisualChildCollection<ScrollBar>(listBox1); foreach (ScrollBar scrollBar in scrollBarList) { if (scrollBar.Orientation == System.Windows.Controls.Orientation.Horizontal) { } else { scrollBar.ValueChanged += new RoutedPropertyChangedEventHandler<double>(verticalScrollBar_ValueChanged); } }