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.Controls.GridView;
using Telerik.Windows.Controls;

namespace TreeGridHybridUsingRowDetails_WPF
{
    public partial class IndentedToggleCell : UserControl
    {
        public IndentedToggleCell()
        {
            InitializeComponent();
            this.toggleButton.Checked += new RoutedEventHandler(toggleButton_Checked);
            this.toggleButton.Unchecked += new RoutedEventHandler(toggleButton_Unchecked);
            this.Loaded += new RoutedEventHandler(IndentedToggleCell_Loaded);
        }

        void IndentedToggleCell_Loaded(object sender, RoutedEventArgs e)
        {
            int indent = 0;
            Person person = (Person)this.DataContext;

            while (person.Parent != null)
            {
                person = person.Parent;
                indent++;
            }

            this.IndentedPanel.Margin = new Thickness(indent * 20, 0, 0, 0);
        }

        void toggleButton_Unchecked(object sender, RoutedEventArgs e)
        {
            this.ParentOfType<GridViewRow>().DetailsVisibility = Visibility.Collapsed;
            this.toggleButton.Content = "+";
        }

        void toggleButton_Checked(object sender, RoutedEventArgs e)
        {
            this.ParentOfType<GridViewRow>().DetailsVisibility = Visibility.Visible;
            this.toggleButton.Content = "-";
        }
    }
}
