Okay, so, everyone knows how to set the scroll position of a ScrollViewer. Entire essays and blog entries have been written about ScrollViewer.ScrollToVerticalOffset(), and there are a good few hundred questions with answers about it here.
So, I enter:
myScrollViewer.ScrollToVerticalOffset(280);
… and it so kindly scrolls to that location.
The question is, what property now contains 280, so I can retrieve it later?
(Hint: myScrollViewer.VerticalOffset and ContentVerticalOffset are both 0; myScrollViewer.ScrollInfo just plain doesn’t exist.)
EDIT: Apparently I need a more detailed demonstration.
private void btnTest_Click(object sender, RoutedEventArgs e) {
double scrollTarget = 280;
MessageBox.Show("Target: " + scrollTarget.ToString());
myScrollViewer.ScrollToVerticalOffset(scrollTarget);
MessageBox.Show("Now: " + myScrollViewer.VerticalOffset);
}
I must reiterate that this does scroll as intended. Goes right exactly where I want it to. But, myScrollViewer.VerticalOffset is set at 0.
The solution is to manually call
myScrollViewer.UpdateLayout()aftermyScrollViewer.ScrollToVerticalOffset(). Then,myScrollViewer.VerticalOffsetwill have the expected value.