Further to Gerry's solution link, I am expecting you to ask how to get the visible Rows. Here is a solution from
Wpf DataGrid: how to detect the set of visible cells?
[
^]
Wire up the event:
<DataGrid ScrollViewer.ScrollChanged="DataGrid_ScrollChanged">
Now the event handler:
private static T GetChildOfType<T>(DependencyObject depObj)
where T : DependencyObject
{
if (depObj == null) return null;
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
{
var child = VisualTreeHelper.GetChild(depObj, i);
var result = (child as T) ?? GetChildOfType<T>(child);
if (result != null) return result;
}
return null;
}
private void DataGrid_ScrollChanged(object sender, ScrollChangedEventArgs e)
{
DataGrid datagrid = sender as DataGrid;
var scroll = GetChildOfType<ScrollViewer>((DependencyObject)sender);
int firstRow = (int)scroll.VerticalOffset;
int lastRow = (int)scroll.VerticalOffset + (int)scroll.ViewportHeight + 1;
for (int i = firstRow; i < lastRow; i++)
{
}
}