.NET Maui - ScrollToAsync not scrolling


I've started looking at .NET Maui recently and ran into an issue almost immediately when putting together a test app. I wanted to add items into a ScrollView and then scroll to the bottom when that occurs.

What I found was, if I called ScrollToAsync once it didn't work. If I called ScrollToAsync twice it wouldn't scroll but then when I manually scrolled with the mouse it would THEN scroll to the end.

Here is a ScrollView extension method that will allow you to scroll a specified View/Control into view.

/// <summary>
/// Scrolls to the specified <see cref="View"/>.
/// </summary>
/// <param name="scrollView"></param>
/// <param name="ctrl"></param>
/// <param name="animate"></param>
public static void ScrollTo(this ScrollView scrollView, View ctrl, bool animate = false)
{
		var timer = new Timer((object obj) => {
				MainThread.BeginInvokeOnMainThread(() => scrollView.ScrollToAsync(ctrl, ScrollToPosition.End, true));
		}, null, 1, Timeout.Infinite);
}

Leave a comment

Please note that we won't show your email to others, or use it for sending unwanted emails. We will only use it to render your Gravatar image and to validate you as a real person.