using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using Telerik.Windows.Controls;
using Telerik.Windows.Controls.GridView;

namespace RowDetailsInTooltip
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();

            this.clubsGrid.ItemsSource = Club.GetClubs();
        }

		private void OnToolTipOpened(object sender, RoutedEventArgs e)
		{
			GridViewRow parentRow = this.GetParentRow(sender);
			parentRow.DetailsVisibility = Visibility.Visible;
		}

		private void OnToolTipClosed(object sender, RoutedEventArgs e)
		{
			GridViewRow parentRow = this.GetParentRow(sender);
			parentRow.DetailsVisibility = Visibility.Collapsed;
		}
		
		private GridViewRow GetParentRow(object sender)
		{
			ToolTip toolTip = (ToolTip)sender;
			Popup popup = (Popup)toolTip.Parent;
			Club club = (Club)popup.DataContext;
			GridViewRow parentRow = (GridViewRow)this.clubsGrid.ItemContainerGenerator.ContainerFromItem(club);
			return parentRow;
		}
	}
}