tags:

views:

236

answers:

1

I was working with ScrollViewer and I noticed that when calling ScrollToHorizontalOffset or ScrollToVerticalOffset that this appears to have a delayed effect in raising the ScrollChanged event. I also noticed that the HorizontalOffset/VerticalOffset properties don't immediately have the value that was just set. After a small amount of time the ScrollChanged event is raised and the properties do have the right values.

Does anyone know the reason for this delayed effect? Why doesn't it update immediately? Is there anyway to force it to update immediately?

+2  A: 

Hi Ashley,

The reason for this delayed effect lies inside ScrollViewer itself. Every time you call ScrollToHorizontalOffset() it adds your request into internal processing queue, which is processed on LayoutUpdated event. To trigger this event ScrollViewer invalidates arrange of inner controls. Only after arrange pass is completed (ArangeOverride() is processed down the visual tree), it raises ScrollChanged event.

Going to your last question: "Is there anyway to force it to update immediately?", I could only advice to make sure content of your ScrollViewer is arranged as fast as possible. I can't think of any other way, which could be easier than this one...

Maybe if you could say why do you need that event to happen immediately we can suggest something better than this answer :)?

Anvaka
Thanks for your answer. I don't really need to have it triggered immediately and it wasn't exactly a problem, I was just curious as to why it works the way it does.
Ashley Davis