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;

namespace HierarchicalDataTemplateWPF
{
    /// <summary>
    /// Interaction logic for HierarchicalDataTemplateSample.xaml
    /// </summary>
    public partial class HierarchicalDataTemplateSample : UserControl
    {
        public HierarchicalDataTemplateSample()
        {
            InitializeComponent();

            // create data object
            var league = League.GetLeague();

            // show it in C1OrgChart
            _chart.Header = league;

            // show it in TreeView
            _tree.ItemsSource = new object[] { league };
        }
    }

    /// <summary>
    /// Top level in the data hierarchy.
    /// </summary>
    public class League
    {
        public string Name { get; set; }
        public List<Division> Divisions { get; set; }

        public static League GetLeague()
        {
            var league = new League();
            league.Name = "Main League";
            league.Divisions = new List<Division>();
            foreach (var div in "North,South,East,West".Split(','))
            {
                var d = new Division();
                league.Divisions.Add(d);
                d.Name = div;
                d.Teams = new List<Team>();
                foreach (var team in "t1,t2,t3,t4".Split(','))
                {
                    var t = new Team();
                    d.Teams.Add(t);
                    t.Name = string.Format("{0} {1}", team, div);
                }
            }
            return league;
        }
    }
    /// <summary>
    /// Middle level in the data hierarchy.
    /// </summary>
    public class Division
    {
        public string Name { get; set; }
        public List<Team> Teams { get; set; }
    }
    /// <summary>
    /// Bottom level in the data hierarchy.
    /// </summary>
    public class Team
    {
        public string Name { get; set; }
    }

    public class foo : HeaderedItemsControl
    {
        protected override void OnItemsSourceChanged(System.Collections.IEnumerable oldValue, System.Collections.IEnumerable newValue)
        {
            base.OnItemsSourceChanged(oldValue, newValue);
        }
        protected override void OnItemsChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            this.ItemTemplate = null;
            this.ItemTemplateSelector = null;
            base.OnItemsChanged(e);
        }
        protected override void OnItemTemplateChanged(DataTemplate oldItemTemplate, DataTemplate newItemTemplate)
        {
            base.OnItemTemplateChanged(oldItemTemplate, newItemTemplate);
        }
        protected override void OnItemTemplateSelectorChanged(DataTemplateSelector oldItemTemplateSelector, DataTemplateSelector newItemTemplateSelector)
        {
            base.OnItemTemplateSelectorChanged(oldItemTemplateSelector, newItemTemplateSelector);
        }
    }

}
