using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Xaml;

namespace OrgChartSamplesLib2013
{
    /// <summary>
    /// Class used to select the templates for items being created.
    /// </summary>
    public class PersonTemplateSelector : C1.Xaml.OrgChart.DataTemplateSelector
    {
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            var p = item as Person;
            //var e = Application.Current.RootVisual as FrameworkElement;
            //return p.Position.IndexOf("Director") > -1
            //    ? e.Resources["_tplDirector"] as DataTemplate
            //    : e.Resources["_tplOther"] as DataTemplate;


            if (p.Position.IndexOf("Director") > -1)
            {
                return DirectorTemplate;
            }
            else if (p.Position.IndexOf("Manager") > -1)
            {
                return ManagerTemplate;
            }
            else if (p.Position.IndexOf("Designer") > -1)
            {
                return DesignerTemplate;
            }
            else
            {
                return OtherTemplate;
            }
        }

        public DataTemplate DirectorTemplate { get; set; }
        public DataTemplate ManagerTemplate { get; set; }
        public DataTemplate DesignerTemplate { get; set; }
        public DataTemplate OtherTemplate { get; set; }
    }
}
