using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows.Controls;
using GridViewColumnSortState;

namespace ErrorAddingNewRecord
{
    public partial class Page : UserControl
    {
        private readonly ObservableCollection<Message> messages = GetMessages();

        public Page()
        {
            this.InitializeComponent();

            this.GridView.ItemsSource = messages;
        }

        private static ObservableCollection<Message> GetMessages()
        {
            return new ObservableCollection<Message>
                       {
                           new Message { Sender = "tom@hanna-barbera.com", Subject = "Cats are cool", Size = 100 },
                           new Message { Sender = "jerry@hanna-barbera.com", Subject = "Mice are cool", Size = 100 },
                           new Message { Sender = "spike@hanna-barbera.com", Subject = "Dogs are cool", Size = 100 }
                       };
        }

        private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            messages.Add(new Message());
        }
    }
}