diff --git a/Source/Collections/AsyncVirtualObservableReadOnlyList.cs b/Source/Collections/AsyncVirtualObservableReadOnlyList.cs index a7d02c4..3c8c042 100644 --- a/Source/Collections/AsyncVirtualObservableReadOnlyList.cs +++ b/Source/Collections/AsyncVirtualObservableReadOnlyList.cs @@ -118,6 +118,8 @@ namespace Nuclex.Avalonia.Collections { /// Resets the enumerator to its initial position public void Reset() { + this.virtualList.requireCount(); // to fix version + this.currentItemIndex = -1; #if DEBUG this.expectedVersion = this.virtualList.version; @@ -532,6 +534,39 @@ namespace Nuclex.Avalonia.Collections { #endif } +#if false + /// Forces the items list to be allocated + /// + /// If your item count is already known by the time the list is constructed, + /// you can call this method in your constructor and avoid potential enumerator + /// version exceptions due to the underlying list changing between enumerator + /// creation and enumerating the first item. + /// + protected void ForceItemAllocation() { + requireCount(); + } + + protected bool IsFetched(int itemIndex) { + requireCount(); + return this.fetchedPages[itemIndex / this.pageSize]; + } +#endif + + /// Retrieves an item by index without triggering a fetch + /// Index of the item that will be retrieved + /// The item at the specified index + /// + /// You can use this method if your lazy-loaded collected has, for example, an extra + /// IsSelected column which the user can toggle on or off. By checking + /// the IsSelected state via this method, you avoid fetching any pages + /// merely to check if the user selected them. You will be exposed to placeholder + /// items (and even null items until I fix this...) + /// + protected TItem GetAtIndexWithoutFetching(int index) { + requireCount(); + return this.typedList[index]; + } + /// Counts the total number of items in the virtual collection /// The total number of items protected abstract int CountItems(); @@ -765,7 +800,7 @@ namespace Nuclex.Avalonia.Collections { private int? assumedCount; /// Number of items to fetch in a single request private readonly int pageSize; - /// Tracks which pages have been fetched so far + /// Tracks which pages have been requested so far private bool[] fetchedPages; /// The wrapped list under its type-safe interface private IList typedList;