using System.Collections.ObjectModel;
using System.Windows;

namespace WPF_RadGridView
{
	public partial class Window1
	{
		public Window1()
		{
			this.InitializeComponent();

		    this.radGridView1.ItemsSource = this.CreatePersonsObservableCollection();
		}

        private ObservableCollection<Person> CreatePersonsObservableCollection()
        {
            var persons = new ObservableCollection<Person>
		              	{
		              		new Person{Age = 30, FirstName = "John", LastName = "Smith"},
		              		new Person{Age = 29, FirstName = "Jane", LastName = "Smith"},
		              		new Person{Age = 30, FirstName = "Peter", LastName = "Smith"}
		              	};
            return persons;
        }

        private void AddNewRow_Click(object sender, RoutedEventArgs e)
        {
            this.radGridView1.BeginInsert();
        }

        private void DeleteCurrentRow_Click(object sender, RoutedEventArgs e)
        {
            Person currentPerson = this.radGridView1.CurrentItem as Person;
            if (currentPerson != null)
            {
                ((ObservableCollection<Person>) this.radGridView1.ItemsSource).Remove(currentPerson);
            }
        }
	}
}