Last active
August 26, 2021 17:40
-
-
Save Char0394/50671267119f2e01015c72597dfb59d2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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