Skip to content

Instantly share code, notes, and snippets.

@damirarh
Last active December 15, 2015 01:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save damirarh/5180926 to your computer and use it in GitHub Desktop.
Save damirarh/5180926 to your computer and use it in GitHub Desktop.
public class IncrementalLoadingBehavior : Behavior<LongListSelector>
{
public ICommand LoadCommand { get; set; }
protected override void OnAttached()
{
base.OnAttached();
AssociatedObject.ItemRealized += OnItemRealized;
}
private void OnItemRealized(object sender, ItemRealizationEventArgs e)
{
var longListSelector = sender as LongListSelector;
if (longListSelector == null)
{
return;
}
var item = e.Container.Content;
var items = longListSelector.ItemsSource;
var index = items.IndexOf(item);
if ((items.Count - index <= 1) && (LoadCommand != null) && (LoadCommand.CanExecute(null)))
{
LoadCommand.Execute(null);
}
}
protected override void OnDetaching()
{
base.OnDetaching();
AssociatedObject.ItemRealized -= OnItemRealized;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment