This project is read-only.


Implement Clear() on VirtualizingVector


Seems like both clear methods should be implemented on here, I did the following:

public void Clear()
        fetchCountCalled = false;

    void IList.Clear()
        fetchCountCalled = false;
Closed Aug 27, 2012 at 10:27 AM by AndyWilkinson
Refresh() methods added to IDataListSource implementations.


AndyWilkinson wrote Jun 23, 2012 at 10:02 AM

The VirtualizingVector list implementation is marked as read-only (IsReadOnly returns 'true') so I had not implemented the Clear() methods to be consistent. There are however valid reasons you might want to be able to clear the internal list (refreshing updated data, clearing cached items to reduce memory pressure, etc.) - out of interest, could you please provide more details on your particular scenario that requires a Clear() method?

Regarding your suggested implementation, there are a couple of thoughts I have. To ensure that any data bound controls are updated then you should raise property and collection changed events after you have cleared the internal list. In addition there is some synchronisation that would be required with any asynchronous requests that are in progress - consider the situation where an item is requested, the Clear method is called, then the item is returned.

I am currently in the process of rearchitecting the data framework to better support certain scenarios and allowing changes to lists is one thing I am looking to include, so any feedback you have on your particular usage would be very interesting.


WhiteWhisker wrote Jun 23, 2012 at 4:31 PM

Yea I realized I put the collection changed in the wrong place, for me the purpose was to reload the data. Thats a great point about the async methods I hadnt considered I will look at that in my implementation. I had created a Reload method inside my DataSource which inherited from VirtualizingDataList that looked like this:

this.OnCollectionChanged( new NotifyCollectionChangedEventArgs( NotifyCollectionChangedAction.Reset ) );

One other change I made was to make dataListSource in VirtualizingDataList protected so I could access it from the datasource and let it know the list had been cleared (to clear out some caching stuff).

AndyWilkinson wrote Jun 25, 2012 at 10:30 AM

That's very useful to understand what you are trying to do. Allowing data lists to support updates is something I'm looking at in the next update of the data framework.


AndyWilkinson wrote Aug 27, 2012 at 10:26 AM

Regarding this issue, there is now a Refresh() method on both SimpleDataListSource<T> and PagedDataListSource<T> that supports refreshing of data. This is the recomended way of refreshing data.