Last active
December 15, 2015 01:38
-
-
Save damirarh/5180926 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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