Question

I have a question regarding the setting of the HorizontalOffset-property (using the ScrollToHorizontalOffset method).

Upon starting my application, the content for the scrollviewer is dynamically created (i.e. I do not know its extent during design-time). I then want to set the horizontal offset of the scrollviewer control, however at that time its scrollable width is returned as 0. Calling UpdateLayout on the scrollviewer does not help either.

I am currently working around this issue by checking the ScrollableWidth property of the scrollviewer control in the rendering event and make a call to ScrollToHorizontalOffset as soon as ScrollableWidth > 0.

This works fine but leads to a short display of the wrong inital position, before in "rendering" the position is adjusted.

Is there anything I can do to force an update on the scrollviewer so that I can set its horizontal offset without this hassle?

Thanks in advance!

Was it helpful?

Solution

Set the opacity of the Content control in the scroll viewer to 0. When you've called ScrollToHorizontalOffset then set the content control's opacity to 1. That way no content is actually seen until its positioned correctly.

OTHER TIPS

Scrollable Height/Width will be zero until the child content is loaded. Until then, it doesn't know how big it needs to be - thus the value of 0.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top