Question

I'm trying to detect when the user starts scrolling down in the xceed grid control. I would like to know what the scrollbar position is, and which rows are currently being displayed on screen (indices would suffice).

Any ideas how I can accomplish this?

Was it helpful?

Solution

For a DataGrid with item based scrolling try this

private void DataGrid_ScrollChanged(object sender, ScrollChangedEventArgs e)
{
    var datagrid = sender as DataGrid;
    var view = CollectionViewSource.GetDefaultView(datagrid.ItemsSource) as CollectionView;

    if (view != null && view.Count > 0)
    {
        int firstIndex = (int)e.VerticalOffset;
        var firstItem = view.GetItemAt(firstIndex);

        int lastIndex = Math.Min(view.Count - 1, (int)(e.VerticalOffset + e.ViewportHeight));
        var lastItem = view.GetItemAt(lastIndex);
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top