Last active
December 25, 2015 15:39
-
-
Save tianhonghui/6999984 to your computer and use it in GitHub Desktop.
LLS with datarequest
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 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