Click here to Skip to main content
13,296,811 members (39,236 online)
Click here to Skip to main content


314 bookmarked
Posted 23 Mar 2009

WPF: Data Virtualization

, 28 Mar 2013
A collection class providing data virtualization with large data sets.
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Threading;

namespace DataVirtualization
    /// <summary>
    /// Interaction logic for DemoWindow.xaml
    /// </summary>
    public partial class DemoWindow
        /// <summary>
        /// Initializes a new instance of the <see cref="DemoWindow"/> class.
        /// </summary>
        public DemoWindow()
            // use a timer to periodically update the memory usage
            DispatcherTimer timer = new DispatcherTimer();
            timer.Interval = new TimeSpan(0, 0, 1);
            timer.Tick += timer_Tick;

        private void timer_Tick(object sender, EventArgs e)
            tbMemory.Text = string.Format("{0:0.00} MB", GC.GetTotalMemory(true)/1024.0/1024.0);

        private void Button_Click(object sender, RoutedEventArgs e)
            // create the demo items provider according to specified parameters
            int numItems = int.Parse(tbNumItems.Text);
            int fetchDelay = int.Parse(tbFetchDelay.Text);
            DemoCustomerProvider customerProvider = new DemoCustomerProvider(numItems, fetchDelay);

            // create the collection according to specified parameters
            int pageSize = int.Parse(tbPageSize.Text);
            int pageTimeout = int.Parse(tbPageTimeout.Text);

            if ( rbNormal.IsChecked.Value )
                DataContext = new List<Customer>(customerProvider.FetchRange(0, customerProvider.FetchCount()));
            else if ( rbVirtualizing.IsChecked.Value )
                DataContext = new VirtualizingCollection<Customer>(customerProvider, pageSize);
            else if ( rbAsync.IsChecked.Value )
                DataContext = new AsyncVirtualizingCollection<Customer>(customerProvider, pageSize, pageTimeout*1000);

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article, along with any associated source code and files, is licensed under A Public Domain dedication


About the Author

Paul McClean
Software Developer (Senior)
United Kingdom United Kingdom
Paul's first venture into software development was on ZX Spectrum BASIC at age 10. Twenty years and a engineering degree later, Paul is a professional software developer based in Northern Ireland.

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.171207.1 | Last Updated 28 Mar 2013
Article Copyright 2009 by Paul McClean
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid