问题
I have a WPF Datagrid (4.0 on Win7). When it is scrolled to very end by dragging (after dragging) the thumb it sometimes returns a bit when released and mouse cursor moves away (probably to start with a complete line). I tried to set CanContentScroll property of DG_ScrollViewer (see WPF DataGrid : CanContentScroll property causing odd behavior) but the grid become unusably slow when populated with lot of data.
The problem doesn't occur when scrolling is done by mouse wheel (after scrolling with wheel) or clicking a scrollbar arrow.
The problem occures also with horizontal scroling.!
回答1:
If found the reason. There was a handler causing the behavior.
Private Sub mMainGrid_PreviewMouseUp(sender As Object, e As System.Windows.Input.MouseButtonEventArgs) Handles MyGrid.PreviewMouseUp
If TypeOf e.OriginalSource Is Thumb Then
MyGrid.Items.Refresh()
End If
End Sub
The aim of this handler is to force refresh a header when a column is resized.
来源:https://stackoverflow.com/questions/10601687/wpf-datagrid-scrolls-up-a-bit-when-scrolled-to-end