0

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?

Filip Frącz
  • 5,881
  • 11
  • 45
  • 67
  • What do you need that for? – Federico Berasategui Jun 14 '13 at 20:46
  • I'm writing an application that will be periodically pulling data from the web and displaying within the grid. I want to fetch the minimum number rows, ie. only the ones needed to be shown at the moment. As soon as the user starts scrolling, I will switch to mode where I fetch more pages of data on demand based on scrollbar position. – Filip Frącz Jun 17 '13 at 14:16

1 Answers1

1

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);
    }
}
LPL
  • 16,827
  • 6
  • 51
  • 95