using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Threading;
using System.ComponentModel;

namespace WpfBusyIndicator
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        BackgroundWorker worker = new BackgroundWorker();
        IEnumerable<Person> data;

        public Window1()
        {
            InitializeComponent();

            SampleGrid.IsBusy = true;
            worker.DoWork += new DoWorkEventHandler(worker_DoWork);
            worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);
            worker.RunWorkerAsync();

        }

        void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            Thread.Sleep(10000);
            data = from c in Enumerable.Range(1, 1000000)
                   select new Person
                   {
                       Age = c % 10,
                       Name = "Name " + c
                   };
        }

        void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            SampleGrid.ItemsSource = data;
            SampleGrid.IsBusy = false;
        }


    }

    public class Person
    {
        public int Age { get; set; }
        public string Name { get; set; }
    }
}
