using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Interactivity;
using Telerik.Windows.Controls;
using Telerik.Windows.Controls.GridView;
using Telerik.Windows.Data;

namespace GridValidation
{
	/// <summary>
	/// Interaction logic for MainWindow.xaml
	/// </summary>
	public partial class MainWindow : Window
	{
		public MainWindow()
		{
			InitializeComponent();
			ViewModel = this;
			var sourceCollection = new List<Item>(Enumerable.Range(0, 10).Select(i => new Item() { Id = i.ToString(), Text = "t" + i }));
			Items = new QueryableCollectionView(sourceCollection);
			IsEditMode = true;
		}

        private void DataGrid_RowEditEnded(object sender, GridViewRowEditEndedEventArgs e)
        {
            if (e.EditAction == GridViewEditAction.Cancel)
            {
                e.UserDefinedErrors.Clear();
            }
        }

		public MainWindow ViewModel
		{
			get { return (MainWindow) DataContext; }
			set { DataContext = value; }
		}

		public QueryableCollectionView Items { get; set; }

		public bool IsEditMode { get; set; }
	}
}
