I have a wpf datagrid (the one from the wpf toolkit), which when there are too many rows to view on the screen it gets a vertical scroll bar. 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 to 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.
It's sort of an overcomplicated way of doing it, but it may work. First, subclass DataGridRowsPresenter and override the OnViewportOffsetChanged method. Then, duplicate the standard control template for the datagrid, and replace the DataGridRowsPresenter with your own. I leave the details of hit testing for a row relative to the viewport up to you ;-).
What are you trying to accomplish, specifically? Maybe we can come up with a better way, as this may be very brittle and requires a bunch of extra work (i.e. keeping the control template in sync if they update it).
By the follow way , I Got it.
Get The HorizontalScrollBar sub class control's instance (mHorizontalScrollBar) .
Get the Total Item Count
nTotalCount = DataGrid1.Items.Count ;
Get First Visible row index
nFirstVisibleRow = mHorizontalScrollBar.Value ;
Get Last visible row Index nLastVisibleRow = nFirstVisibleRow + nTotalCount - mHorizontalScrollBar.Maximum ;