检查可见行的WPF的DataGridWPF、DataGrid

2023-09-02 21:11:56 作者:琴断ら弦奈何

我有一个WPF 的DataGrid ,其中当有太多的行以查看它得到一个垂直滚动条在屏幕上。如果有办法知道顶部可见行是当用户滚动我想知道的是。

I have a WPF DataGrid, which when there are too many rows to view on the screen it gets a vertical scrollbar. What I would like to know is if there is a way to know what the top visible row is when the user is scrolling.

在理想情况下,我想能够要连接一个事件要知道,当用户滚动和滚动,检查顶部可见行是为了更新一些信息是什么。

Ideally I would like to be able to wire up an event to know when the user is scrolling and on scroll, check what the top visible row is in order to update some information.

推荐答案

使用下面的方法为我工作:

Using the following method worked for me:

// mHorizontalScrollBar is the HorizontalScrollBar subclass control's instance

// Get the total item count
nTotalCount = DataGrid1.Items.Count; 

// Get the first visible row index 
nFirstVisibleRow = mHorizontalScrollBar.Value;

// Get the last visible row index
nLastVisibleRow = nFirstVisibleRow + nTotalCount - mHorizontalScrollBar.Maximum;