質問

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?

役に立ちましたか?

解決

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);
    }
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top