アイテムが多すぎる ListBox があり、UI がどんどん遅くなります (仮想化がオンになっているなど)。そのため、最初の 20 項目のみを表示し、ユーザーが結果セット (つまり、ObservableCollection) をナビゲートできるようにすることを考えていました。
ObservableCollection にページネーション メカニズムが存在するかどうかは誰にもわかりませんか? 誰もそれをやったことがありますか?
ありがとう!
アイテムが多すぎる ListBox があり、UI がどんどん遅くなります (仮想化がオンになっているなど)。そのため、最初の 20 項目のみを表示し、ユーザーが結果セット (つまり、ObservableCollection) をナビゲートできるようにすることを考えていました。
ObservableCollection にページネーション メカニズムが存在するかどうかは誰にもわかりませんか? 誰もそれをやったことがありますか?
ありがとう!
この機能は、基本 ObservableCollecton クラスでは直接利用できません。ObservableCollection を拡張して、これを行うカスタム コレクションを作成できます。この新しいクラス内に元のコレクションを非表示にし、FromIndex および ToIndex に基づいて、アイテムの範囲を動的にクラスに追加する必要があります。InsertItem と RemoveItem をオーバーライドします。テストされていないバージョンを以下に示します。ただし、これは単なる疑似コードとして受け取ってください。
//This class represents a single Page collection, but have the entire items available in the originalCollection
public class PaginatedObservableCollection : ObservableCollection<object>
{
private ObservableCollection<object> originalCollection;
public int CurrentPage { get; set; }
public int CountPerPage { get; set; }
protected override void InsertItem(int index, object item)
{
//Check if the Index is with in the current Page then add to the collection as bellow. And add to the originalCollection also
base.InsertItem(index, item);
}
protected override void RemoveItem(int index)
{
//Check if the Index is with in the current Page range then remove from the collection as bellow. And remove from the originalCollection also
base.RemoveItem(index);
}
}
更新: このトピックに関するブログ投稿がhttp://jobijoy.blogspot.com/2008/12/paginated-observablecollection.htmlにあり、ソース コードはCodeplexにアップロードされています。