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;
namespace SilverlightApplication1
{
public class ListBoxScrollPage
{
private static volatile ListBoxScrollPage instance;
private static object syncObj = new object();
public ListBoxScrollPage()
{
}
public static ListBoxScrollPage Instance
{
get
{
if (null == instance)
{
lock (syncObj)
{
if (null == instance)
{
instance = new ListBoxScrollPage();
}
}
}
return instance;
}
}
///
/// 使用视图树根据给定的子元素类型,从对象中查找子元素
///
///
///
///
private T FindChildOfType(DependencyObject element)
where T : class
{
if (null != element)
{
if (element is T)
return (element as T);
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(element); i++)
{
DependencyObject child = VisualTreeHelper.GetChild(element, i);
T grandChild = FindChildOfType(child);
if (null != grandChild)
return grandChild;
}
}
return null;
}
///
/// 根据ScrollBar分页
///
///
///
public void PageByScroll(ListBox current, RoutedPropertyChangedEventHandler scrollBar_ValueChanged)
{
ScrollBar scrollBar = FindChildOfType(current);
if (null != scrollBar && scrollBar.Orientation != System.Windows.Controls.Orientation.Horizontal)
{
scrollBar.ValueChanged += scrollBar_ValueChanged;
}
}