views:

402

answers:

1

Hi,

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!

+2  A: 

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.

AnthonyWJones
This works, of course - but is this really the only way of "solving" the original problem?
Grimtron
@Grimtron: None this simple.
AnthonyWJones
Try interacting with the ScrollViewer in its Loaded event.
Adel Hazzah