using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections;

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

			radTreeView.ItemsSource = new MyViewModel[]
			{
			    new MyViewModel()
			    { 
			        Header = "Sport Categories", 
			        Path = "SC",
			        Children = new MyViewModel[]
			        {
			            new MyViewModel()
			            {
			                Header = "Football",
			                Path = "F",
			                Children = new MyViewModel[]
			                {
			                    new MyViewModel()
			                    {
			                        Header = "Futsal",
			                        Path = "H",
			                    },
			                    new MyViewModel()
			                    {
			                        Header = "Soccer",
			                        Path = "S",
			                    }
			                }
			            },
			            new MyViewModel()
			            {
			                Header = "Tennis",
			                Path = "T",
			            },
			            new MyViewModel()
			            {
			                Header = "Cycling",
			                Path = "C",
			            }
			        }
			    }
			};

			Loaded += new RoutedEventHandler(MainPage_Loaded);
		}

		void MainPage_Loaded(object sender, RoutedEventArgs e)
		{
			Dispatcher.BeginInvoke(SelectItemByPath);
		}

		private void SelectItemByPath()
		{
			//var path = "Sport Categories|Football|Soccer";
			var path = "SC|F|S";
			//radTreeView.ExpandItemByPath(path, "|");
			radTreeView.GetItemByPath(path, "|").IsSelected = true;
		}
	}

	public class MyViewModel
	{
		public string Path { get; set; }
		public string Header { get; set; }
		public IEnumerable Children { get; set; }
	}


}
