分页方法:
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);
}
}