You must adapt the implementation of VirtualizingCollection, please check the following article http://www.codeproject.com/Articles/34405/WPF-Data-Virtualization .
I wrote an sample application using an adaptation of VirtualizingCollection for Windows Phone 8.1 Runtime App.
public class ThumbnailItem
{
public Uri ImageUri { get; set; }
}
Later write the ThumbnailItem provider.
public class ThumbnailProvider : IItemsProvider<ThumbnailItem>
{
private readonly int _itemsCount;
public ThumbnailProvider(int itemsCount)
{
_itemsCount = itemsCount;
}
public int FetchCount()
{
return _itemsCount;
}
public IList<ThumbnailItem> FetchRange(int startIndex, int count)
{
var items = new List<ThumbnailItem>();
while (count-- > 0)
{
items.Add(new ThumbnailItem()
{
ImageUri = new Uri("ms-appx:///Assets/Square71x71Logo.scale-240.png")
});
}
return items;
}
}
Then, inside your ViewModel, you must create a IList property and set the value using an implementation of VirtualizingCollection. I suggest you use AsyncVirtualizingCollection.
Items = new AsyncVirtualizingCollection<ThumbnailItem>(new ThumbnailProvider(1000000), 100);
Finally, on the view you must set the DataContext object using an instance of your ViewModel and your ListView should look similar to:
<ListView
ItemsSource="{Binding Items,Mode=OneWay}"
VirtualizingStackPanel.VirtualizationMode="Recycling">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<WrapGrid Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemTemplate>
<DataTemplate>
<Grid Margin="0 0 20 20">
<Image Source="{Binding ImageUri,Mode=OneTime}"
Width="72" Height="72"/>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
Of course, the logic of the provider must be changed according your requierements, the code I wrote is just a sample.
Please, mark it as answer if helped you.
Best regards,
Denys
EDIT
Friend @Quincy, I posted a simple example, you can adapt it. Maybe for your application the ThumbnailItem class will contain the Filename property indicating the IsolateStorageFile filename. In that case you must create a Binding with converter, so you needs to implement an IValueConverter object to create a BitmapImage instance using the IsolateStorageFile.
BitmapImage image = new BitmapImage();
image.SetSource(sourceFile);
return image;
About image closing, the VirtualizingCollection has defined a pagesize, 100 by default. Yours IsolateStorageFiles will be used one time to create the BitmapImage in your IValueConverter object. Later the VirtualizingCollection will delete old pages if they are not in use(not displayed, check VirtualizingCollection implementation), and finally the GC will close&dispose the BitmapImage.
Porting VirtualizingCollection is easy, I remember I just did changes on AsyncVirtualizingCollection class. My solution was simple:
Replace ThreadPool.QueueUserWorkItem for ThreadPool.RunAsync.
Replace Trace for Debug (just debug messages, not really important).
Replace SynchronizationContext methods invocation by using:
(for windows phone app) CoreApplication.MainView.CoreWindow.Dispatcher.
(for windows app) CoreApplication.MainView.Dispatcher.
I hope it helps you.