Skip to content

Instantly share code, notes, and snippets.

@Char0394
Last active August 26, 2021 17:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Char0394/50671267119f2e01015c72597dfb59d2 to your computer and use it in GitHub Desktop.
Save Char0394/50671267119f2e01015c72597dfb59d2 to your computer and use it in GitHub Desktop.
public class ExtendedListView : ListView, IDisposable
{
public static readonly BindableProperty LoadMoreCommandProperty =
BindableProperty.Create(nameof(LoadMoreCommand), typeof(ICommand), typeof(ExtendedListView), default(ICommand));
public ICommand LoadMoreCommand
{
get { return (ICommand)GetValue(LoadMoreCommandProperty); }
set { SetValue(LoadMoreCommandProperty, value); }
}
public ExtendedListView() : this(ListViewCachingStrategy.RetainElement)
{
}
public ExtendedListView(ListViewCachingStrategy cachingStrategy) : base(cachingStrategy)
{
ItemAppearing += OnItemAppearing;
}
private void OnItemAppearing(object sender, ItemVisibilityEventArgs e)
{
if (LoadMoreCommand != null)
{
if (e.Item == ItemsSource.Cast<object>().Last())
{
LoadMoreCommand?.Execute(null);
}
}
}
public void Dispose()
{
ItemAppearing -= OnItemAppearing;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment