using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Telerik.Windows.Controls;
using System.Collections;

namespace FilteringByCustomTypeSilverlight
{
    public partial class Page2 : UserControl
    {
        public Page2()
        {
            InitializeComponent();

            this.Loaded += new RoutedEventHandler(Page2_Loaded);
        }

        void Page2_Loaded(object sender, RoutedEventArgs e)
        {
            // Get the data for the GridView control
            this.GridView.ItemsSource = GetData();
        }

        private DataTable GetData()
        {
            DataTable table = new DataTable();

            // Build a dynamic table with one column
            DataColumn column = new DataColumn();
            column.ColumnName = "GmailMessage";
            table.Columns.Add(column);

            // Loop through Stefan Dobrev's list of messages and toss the Message object into the dynamic table
            foreach (Message message in GetMessages())
            {
                DataRow row = new DataRow();
                row["GmailMessage"] = message;
                table.Rows.Add(row);
            }

            return table;
        }

        private IList<Message> GetMessages()
        {
            return new[]
                       {
                           new Message
                               {
                                   Sender = "tom@hanna-barbera.com",
                                   Subject = "Cats are cool",
                                   Size = 100,
                                   Attachment = new Attachment { Name = "Attach1" }
                               },
                           new Message
                               {
                                   Sender = "jerry@hanna-barbera.com",
                                   Subject = "Mice are cool",
                                   Size = 100,
                                   Attachment = new Attachment { Name = "Attach1" }
                               },
                           new Message
                               {
                                   Sender = "spike@hanna-barbera.com",
                                   Subject = "Dogs are cool",
                                   Size = 100,
                                   Attachment = new Attachment { Name = "Attach2" }
                               }
                       };
        }
    }
}
