// // Slow data is ready. // // This call occurs after the worker thread is complete and the results // are ready. // // NOTE: THIS CALL CAN HAPPEN AFTER THE VIRTUAL LIST HAS BEEN DISPOSED. // // Take care during this type of callback. It's asynchronous and you can't // make assumptions about the validity of the virtual list (or the data items // within it). // private void StoreSlowData(object args) { SlowDataResult result = (SlowDataResult)args; // // Remove tracking for pending picture acquires. // _pendingPictureAcquires.Remove(result.Index); // // If the VirtualList has been disposed before this callback is received, // or if the data item specified by the index has been thrown away, then // clean up the picture file. // // Note that we need to check IsItemAvailable() instead of just calling // the indexer and checking for null. This is because doing that query // can cause the item to be faulted in after it'd already been thrown // away due to going offscreen. // if (IsDisposed || !IsItemAvailable(result.Index)) { if (result.PicturePath != null) { File.Delete(result.PicturePath); } return; } // // All is well, tell the ThumbnailData about this new picture. // ThumbnailData t = (ThumbnailData)this[result.Index]; t.SetPicture(result.PicturePath); }
// // Item Request // // The repeater is ready to build visuals for the data at the specified // index. An index is queried if the visual representation of that item // is ready to be displayed. You are given a delegate to call back on // to report the data item. // // NOTE: Never block within this call and always call the callback delegate // on this (the application) thread! // // Depending on your data situation, you may choose to: // // 1) Call the callback immediately (recommended): // // If you call the callback immediately, your are providing the required // data item right now. However, you don't have to guarantee that the // data item is complete (in which case, you can fill in with "placeholder" // data). The benefit of an immediate return (even if it's partial data) is // that there will always be something on the screen for the user to see and // interact with. // // In general, you should build a data item and populate it with only // data that can be queried quickly. Any data that is too slow to get // during this call should be provided in the "update" callback. // // 2) Call callback at a later time: // // If you call the callback later, the negative is that the user will // see a "hole" in the list while you fetch the data on a worker thread. // Although this is supported, it's not recommended. Make sure to always // call the callback back on the main application thread. // protected override void OnRequestItem(int index, ItemRequestCallback callback) { // // Build the data item and initialize it with data that // is quick to get (in this case, the caption). // // Notice how the VirtualList is passed to the ThumbnailData. This is // so every ModelItem created (in this case, the ThumbnailData) gets // assigned an owner. This is important since when the VirtualList gets // disposed, the ThumbnailData will also get disposed automatically. // ThumbnailData t = new ThumbnailData(this, index.ToString(CultureInfo.CurrentUICulture)); // // Inform the list. // callback(this, index, t); }