Neutral Scent

App developments & Gadgets

スクロールでオートロードするListBox (簡易版)

リストの最後まで読むと自動的にさらに先を読み込んでくれるリストボックスが最近の流行りだと思うんですが、Silverlightで単純にやろうとすると、ScrollViewerやお手軽なイベント、プロパティがぱっと手の届くところにありません。なので、コードビハインド側でできるだけ単純に実装した時、というサンプルです。



public MainPage()
{
InitializeComponent();

FirstListBox.ManipulationCompleted += new EventHandler<ManipulationCompletedEventArgs>(FirstListBox_ManipulationCompleted);
}

void FirstListBox_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
{
ScrollViewer scrollViewer = FindChildOfType<ScrollViewer>(FirstListBox);
if (scrollViewer != null && scrollViewer.VerticalOffset >= (scrollViewer.ScrollableHeight))
App.ViewModel.LoadData();
}

コントロール等はPivotテンプレートにそのまま差し込んだ状態です。
LoadData()を呼ぶ度にViewModelに増分をロードしてくるコードが仕込んであるイメージで。
タイミングやロードの仕方はいろいろあると思うので工夫してみてください。