Skip to content

Instantly share code, notes, and snippets.

@tianhonghui
Last active December 25, 2015 15:39
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tianhonghui/6999984 to your computer and use it in GitHub Desktop.
Save tianhonghui/6999984 to your computer and use it in GitHub Desktop.
LLS with datarequest
using System;
using System.Windows;
using Microsoft.Phone.Controls;
namespace Sample.Controls {
public class MTLonglistselector : LongListSelector {
public MTLonglistselector() {
ItemRealized += OnItemRealized;
}
public static readonly DependencyProperty IsLoadingProperty =
DependencyProperty.Register("IsLoading", typeof(bool), typeof(MTLonglistselector), new PropertyMetadata(default(bool)));
public bool IsLoading {
get { return (bool)GetValue(IsLoadingProperty); }
set { SetValue(IsLoadingProperty, value); }
}
private const int Offset = 2;
public event EventHandler DataRequest;
protected virtual void OnDataRequest() {
EventHandler handler = DataRequest;
if (handler != null) handler(this, EventArgs.Empty);
}
private void OnItemRealized(object sender, ItemRealizationEventArgs itemRealizationEventArgs) {
if (!IsLoading && ItemsSource != null && ItemsSource.Count >= Offset) {
if (itemRealizationEventArgs.ItemKind == LongListSelectorItemKind.Item) {
var offsetItem = ItemsSource[ItemsSource.Count - Offset];
if ((itemRealizationEventArgs.Container.Content == offsetItem)) {
OnDataRequest();
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment