当datagrid的滚动条拉到4/3的时候去加载数据。。

public MainWindow()
{
InitializeComponent(); for (int i = ; i <= ; i++)
{
Class1 c1 = new Class1();
c1.Name = "sadada" + i;
dg.Items.Add(c1);
} }
private static T GetVisualChild<T>(DependencyObject parent) where T : Visual
{
T child = default(T);
int numVisuals = VisualTreeHelper.GetChildrenCount(parent);
for (int i = ; i < numVisuals; i++)
{
Visual v = (Visual)VisualTreeHelper.GetChild(parent, i);
child = v as T;
if (child == null)
{
child = GetVisualChild<T>(v);
}
if (child != null)
{
break;
}
}
return child;
}
int data = ;
private void dg_LayoutUpdated(object sender, EventArgs e)
{
ScrollViewer scrollViewer = GetVisualChild<ScrollViewer>(dg);
double Position = scrollViewer.ContentVerticalOffset;
if (Position >= data) //当拖动的数据条数超过的时候再去加
{
for (int i = ; i <= ; i++)
{
Class1 c1 = new Class1();
c1.Name = "sadada" + i;
dg.Items.Add(c1);
}
data += ;
} }

WPF、AE技术交流群:94234450

不管你遇到了什么问题,我们都不会让你独自去面对!

群链接:http://wp.qq.com/wpa/qunwpa?idkey=14e3d476b4a53a3a1502183e5a384d94b8be74b7510c0a76e67c4dec61f23781

05-11 13:32