Last active
October 3, 2019 15:51
-
-
Save jamesmontemagno/465ced24fc8a206dcaf3 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
using System; | |
using Xamarin.Forms; | |
using System.Collections.ObjectModel; | |
using System.Threading.Tasks; | |
namespace LoadMoreBottom | |
{ | |
public class App : Application | |
{ | |
ObservableCollection<string> Items; | |
bool isLoading; | |
Page page; | |
public App () | |
{ | |
Items = new ObservableCollection<string> (); | |
var listview = new ListView (); | |
listview.ItemsSource = Items; | |
listview.ItemAppearing += (sender, e) => | |
{ | |
if(isLoading || Items.Count == 0) | |
return; | |
//hit bottom! | |
if(e.Item.ToString() == Items[Items.Count - 1]) | |
{ | |
LoadItems(); | |
} | |
}; | |
// The root page of your application | |
page = new ContentPage { | |
Content = new StackLayout { | |
VerticalOptions = LayoutOptions.Center, | |
Children = { | |
listview | |
} | |
} | |
}; | |
MainPage = new NavigationPage (page); | |
LoadItems (); | |
} | |
private async Task LoadItems() | |
{ | |
isLoading = true; | |
page.Title = "Loading"; | |
//simulator delayed load | |
Device.StartTimer (TimeSpan.FromSeconds (2), () => { | |
for (int i = 0; i < 20; i++) { | |
Items.Add (string.Format("Item {0}", Items.Count)); | |
} | |
page.Title = "Done"; | |
isLoading = false; | |
//stop timer | |
return false; | |
}); | |
} | |
protected override void OnStart () | |
{ | |
// Handle when your app starts | |
} | |
protected override void OnSleep () | |
{ | |
// Handle when your app sleeps | |
} | |
protected override void OnResume () | |
{ | |
// Handle when your app resumes | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It appears that when doing a rapid motion scroll - the 'if(e.Item.ToString() == Items[Items.Count - 1])' part doesn't seem to evaluate to true... any clue as to why?