ScrollViewer.VerticalOffset is used to get a value that contains the vertical offset of the scrolled content, it has no set method, you can't set a value to it directly , you can refer to ScrollViewer.VerticalOffset Property for more info. You can use ScrollToVerticalOffset
to the specified vertical offset position and set IsDeferredScrollingEnabled = true
to keep the content is stationary when the user drags the Thumb of a ScrollBar.
Please add SizeChanged
event and Loaded
event to your DataGrid
, and implment below code in cs:
ScrollViewer sv1;
private void dataGrid_SizeChanged(object sender, SizeChangedEventArgs e)
{
sv1 = VisualTreeHelper.GetChild(VisualTreeHelper.GetChild(this.dataGrid, 0), 0) as ScrollViewer;
sv1.IsDeferredScrollingEnabled = true;
sv1.ScrollToVerticalOffset(123);
}
private void dataGrid_Loaded(object sender, RoutedEventArgs e)
{
sv1 = VisualTreeHelper.GetChild(VisualTreeHelper.GetChild(this.dataGrid, 0), 0) as ScrollViewer;
sv1.IsDeferredScrollingEnabled = true;
sv1.ScrollToVerticalOffset(123);
}
By the way, if I misunderstand your question, please point out.
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.