using System;
using System.Windows;
using Telerik.Windows.Controls;

namespace ConfirmationPromptOnCellEditEnded
{
	/// <summary>
	/// Interaction logic for MainWindow.xaml
	/// </summary>
	public partial class MainWindow : Window
	{
		int oldNumber;
		int newNumber;

		public MainWindow()
		{
			InitializeComponent();			
		}		

		private void playersGrid_CellEditEnded(object sender, GridViewCellEditEndedEventArgs e)
		{
			if (e.EditAction == Telerik.Windows.Controls.GridView.GridViewEditAction.Cancel)
				return;

			oldNumber = (int)e.OldData;
			newNumber = (int)e.NewData;

			// nothing has changed
			if (oldNumber == newNumber)
				return;

			RadWindow.Confirm("Are you sure you want to change this number - " + oldNumber + " to this number - " + newNumber + "?", this.ChangeNickname);
		}

		private void ChangeNickname(object sender, WindowClosedEventArgs e)
		{
			(this.playersGrid.SelectedItem as Player).Number = newNumber;
		
		}
	}
}
