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 System.ComponentModel;
using System.Collections.ObjectModel;

namespace AddNewRowAttachedBehavior
{
	public partial class MainPage : UserControl
	{
		public MainPage()
		{
			InitializeComponent();
			this.RadGridView1.ItemsSource = Person.GetSampleObservableCollectionOfPersons();
		}
	}

	public class Person : INotifyPropertyChanged
	{
		private string firstName;
		private string lastName;
		private int age;

		public event PropertyChangedEventHandler PropertyChanged;

		public Person()
		{
			this.age = 0;
			this.firstName = String.Empty;
			this.lastName = String.Empty;
		}

		public Person(int age, string firstName, string lastName)
		{
			this.age = age;
			this.firstName = firstName;
			this.lastName = lastName;
		}

		public int Age
		{
			get
			{
				return this.age;
			}
			set
			{
				if (this.age != value)
				{
					this.age = value;
					this.OnPropertyChanged("Age");
				}
			}
		}

		public string FirstName
		{
			get
			{
				return this.firstName;
			}
			set
			{
				if (this.firstName != value)
				{
					this.firstName = value;
					this.OnPropertyChanged("FirstName");
				}
			}
		}

		public string LastName
		{
			get
			{
				return this.lastName;
			}
			set
			{
				if (this.lastName != value)
				{
					this.lastName = value;
					this.OnPropertyChanged("LastName");
				}
			}
		}

		public static ObservableCollection<Person> GetSampleObservableCollectionOfPersons()
		{
			var persons = new ObservableCollection<Person>
			              	{
			              		new Person(30, "John", "Smith"),
			              		new Person(29, "Jane", "Smith"),
			              		new Person(30, "Peter", "Smith")
			              	};
			return persons;
		}

		private void OnPropertyChanged(string property)
		{
			if (this.PropertyChanged != null)
				this.PropertyChanged(this, new PropertyChangedEventArgs(property));
		}
	}
}
