using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Telerik.Windows.Data;
using Telerik.Windows.Controls;
using Telerik.Windows.Controls.GridView;
using System.ComponentModel;
using Telerik.Windows;

namespace RadGridView_WPF_AR_5
{
	/// <summary>
	/// Interaction logic for MainWindow.xaml
	/// </summary>
	public partial class MainWindow : Window, INotifyPropertyChanged
	{
		public event PropertyChangedEventHandler PropertyChanged;

		private GridViewCellBase clickedCell;
		public GridViewCellBase ClickedCell
		{
			get
			{
				return clickedCell;
			}
			set
			{
				clickedCell = value;
				if (this.PropertyChanged != null)
				{
					this.PropertyChanged(this, new PropertyChangedEventArgs("ClickedCell"));
				}
			}
		}

		public MainWindow()
		{
			InitializeComponent();
		
			this.playersGrid.RowLoaded += new EventHandler<RowLoadedEventArgs>(playersGrid_RowLoaded);
			this.playersGrid.AddHandler(GridViewCellBase.CellDoubleClickEvent, new EventHandler<RadRoutedEventArgs>(OnCellDoubleClick), true);
		}

		void playersGrid_RowLoaded(object sender, RowLoadedEventArgs e)
		{
			if (e.Row is GridViewHeaderRow || e.Row is GridViewNewRow || e.Row is GridViewFooterRow)
				return;

			var row = e.Row as GridViewRow;

			DoubleClick click = new DoubleClick(row);
			click.DoubleClickEvent += new System.EventHandler(click_DoubleClickEvent);
		}

		private void click_DoubleClickEvent(object sender, EventArgs e)
		{
		}
		
		private void OnCellDoubleClick(object sender, RadRoutedEventArgs args)
		{
			GridViewCellBase cell = args.OriginalSource as GridViewCellBase;
			if (cell != null)
			{
				this.ClickedCell = cell;
				var correspondingColumn = cell.Column;
				var correspondingRow = cell.ParentOfType<GridViewRow>();
				var rowIndex = this.playersGrid.ItemContainerGenerator.IndexFromContainer(correspondingRow);
			}
		}						
	}
}