Forum Xamarin.Forms

Is it possible to wait for content to be rendered before attempting a ScrollView scroll?


Within a ContentPage (after it's been displayed), I'd like to have a user action generate a ScrollView (on the same page), add controls to it (via a vertically-oriented StackLayout), and then immediately scroll to a specific control that the user had selected. Ideally, the scroll would occur just before the user interacts with the ScrollView.

My plan is to locate the control among the StackLayout children in order to obtain the Y position. Then I use that to scroll the ScrollView. This works fine if I scroll from an already created ScrollView with controls.

The problem I'm running into is that now I attempt the scroll after my 'DrawLayout' method is executed, but apparently before the controls are rendered (ie. their y positions are still 0). Is there a way to wait on the rendering of the ScrollView's content after dynamically creating it?



  • As a workaround, even though the code is already running on the main thread, I explicitly wrap the scroll step in a Device.BeginInvokeOnMainThread block. I suppose that enqueues the scroll action to be performed during the next run loop cycle.

Sign In or Register to comment.