Scrolling Programmatically and Manually

Nathan Sokalski 4,116 Reputation points
2020-02-20T06:42:10.543+00:00

I have a UWP app which contains a ScrollViewer. The ScrollViewer will be scrolled both programmatically and by the user. When the ScrollViewer is resized (whether by modifying the layout of other components or the user resizing the window), I want to programmatically scroll to the current item only if that is how it was most recently scrolled. However, if the user manually scrolled to a position, I do not want to scroll (I want to leave it wherever it ended up). I thought the best way to do this would be using the LayoutUpdated event. However, because LayoutUpdated is triggered multiple times, as are events of the ScrollViewer (ViewChanged, ViewChanging, etc.) it is hard to know when to specify whether I want the ScrollViewer to be automatically updated with a size or layout change. What would be a good way to do this? Thanks.

Universal Windows Platform (UWP)
{count} votes