I have a ListView which consists of Custom Renderers. I want the user to scroll to the bottom of the ListView on entering the page.
Since my content is binded, it seems that OnAppearing is fired too soon (before my ListView is loaded). How can I fire off ScrollToLast() at the right time?
protected override void OnAppearing()
{
base.OnAppearing();
this.ItemsListView.ScrollToLast();
}
public class CustomListView : ListView
{
public CustomListView() : this(ListViewCachingStrategy.RecycleElement)
{
ScrollToLast();
}
public CustomListView(ListViewCachingStrategy cachingStrategy)
: base(cachingStrategy)
{
}
public void ScrollToLast()
{
try
{
if (ItemsSource != null && ItemsSource.Cast<object>().Count() > 0)
{
var lastItem = ItemsSource.Cast<object>().LastOrDefault();
if (lastItem != null)
{
ScrollTo(lastItem, ScrollToPosition.End, false);
}
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.ToString());
}
}
}