anagram4wander / VirtualizingObservableCollection

.NET PCL With Virtualizing Observable Collection
http://alphachitech.wordpress.com/2015/01/31/virtualizing-observable-collection/
56 stars 28 forks source link

VirtualizingObservableCollection.Add does not add 0th item. #16

Open YellowJacket86 opened 8 years ago

YellowJacket86 commented 8 years ago

VirtualizingObservableCollection.Add calls InternalAdd, which uses the Provider or ProviderAsync as IEditableProvider. In this case, that method is PaginationManager.OnAppend. PaginationManager.OnAppend determines the page to use. If the call to IsPageWired succeeds, the item gets added. Otherwise, it does not. In both cases, the _LocalCount gets updated, and for cases where the provider is async, a test GetAt is performed - that function will ultimately call SafeGetPage, which will cause the page to get "wired"

The result is, the 0th item does not get added because the page is not "wired", but subsequent items for async providers get added because the test GetAt wires the page via a call to SafeGetPage.

OnInsert, OnRemove and OnReplace all follow that pattern. Is there any reason to not just call SafeGetPage instead of the "wired" check?

I am using an asynchronous provider derived from PagedSourceProviderMakeAsync where I have implemented _FuncGetItemsAt and friends to retrieve records from cache as requested. Should I be using Add, Insert, etc. functions on the VisualiziingObservableCollection object? So far, that is the only way I have found I can make the item count update without calling OnReset with either -1 or my packet count, which results in bad things when receiving data at a high rate....

YellowJacket86 commented 8 years ago

I "solved" the problem by trying to assign a record to the 0th entry, and just eating the exception that is thrown. That wires the page so that the first Add works.

Now I see that the scroll performance of my DataGrid is terrible while adding records. I am adding thousands per minute, and will have totals in the millions. The scroll performance of a regular ObservableCollection is great, but once I get above 350,000 or so records, I run out of memory (hence the desire to virtualize the data). Suggestions?