In general the values of HorizontalOffset
and VerticalOffset
are not updated except during the LayoutUpdated
event after the ScrollContentPresenter
(or other IScrollInfo
) has updated its value and called InvalidateScrollInfo(). The one exception is that the DependencyProperty for each of these is updated during deferred scrolling (but surprisingly the corresponding CLR property is not updated), but this probably does not apply in your case.
There are no ScrollToHorizontalOffset
or ScrollToVerticalOffset events in WPF, but there is both a ScrollViewer method and a RoutedCommand of these names. Both the command version and the method version remember your request and execute it at the next
LayoutUpdated` event, so if all you want to do is make sure the scrolling happens, just send the command or call the method.
If you want to verify that HorizontalOffset
or VerticalOffset
has indeed been updated as desired you can simply catch the ScrollChangedEvent
, which fires after the values have been updated, like this:
scrollViewer.ScrollChanged += (obj, e) =>
{
// Get offset information from 'e' or from scrollViewer
}
I did not understand what you meant by "I have tried LayoutUpdated() method but it goes in a infinite loop," since you didn't explain what "LayoutUpdated() method" is, but the above information should make the order of events clear and help you on your way to a solution. In any case, all the information you need to make your decision should be available from the ScrollChanged
event.