njsokalski avatar image
0 Votes"
njsokalski asked ·

Scrolling Programmatically and Manually

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.

· 8
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I'm confused about your expected behavior. Do you mean when the ScrollViewer is resized, if the most recent scrolling method was scrolling programmatically, then scroll to a specific item, but if the most recent scrolling method was scrolling by user, then don't scroll to the specific item? Can you show more details about your expected behavior and show some code snippet that you currently implement?

0 Votes 0 · ·

What you said is exactly what I want, I am just having trouble figuring out how to make it happen (what events to use, and how/when to remember what the last kind of scrolling was).

0 Votes 0 · ·

There is no directly method could judge what the last kind of scrolling was. But you could try to listen the user's behavior. For example, you can subscribe the PointerWheelChangedEvent and declare a property of bool type. If the user uses mouse to trigger the scrolling of scrollViewer and you can set the property to true. If you trigger the scrolling of scrollViewer programmatically, you can set the property to false. And when the size of window changes, according to the property to determine if scrolling the scrollviewer to the specific position.

0 Votes 0 · ·

Hi, can this help you? Do you have other questions?

0 Votes 0 · ·

Hi, is there any update?

0 Votes 0 · ·

Hi, is there any update? Have you solved your issue?

0 Votes 0 · ·
Show more comments

0 Answers