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

namespace TriStateModeInDeep
{
	public partial class MainPage : UserControl
	{
		private SampleViewModel sampleVM;
		private SampleViewModel sampleVM2;
		public MainPage()
		{
			InitializeComponent();

			this.sampleVM = new SampleViewModel();
			this.sampleVM2 = new SampleViewModel();
			this.treeView.DataContext = this.sampleVM;
			this.treeView2.DataContext = this.sampleVM2;
		}

		private void CheckButton_Click(object sender, RoutedEventArgs e)
		{
			SampleBusinessObject item = this.sampleVM[1].Items[1];
			if (item.IsChecked == true)
				item.IsChecked = false;
			else if (item.IsChecked == false)
				item.IsChecked = true;
			else
				item.IsChecked = null;
		}

		private void CheckButton2_Click(object sender, RoutedEventArgs e)
		{
			SampleBusinessObject item = this.sampleVM2[1].Items[1];
			if (item.IsChecked == true)
				item.IsChecked = false;
			else if (item.IsChecked == false)
				item.IsChecked = true;
			else
				item.IsChecked = null;
		}

		private void treeView_Selected(object sender, Telerik.Windows.RadRoutedEventArgs e)
		{
			RadTreeViewItem container = e.OriginalSource as RadTreeViewItem;
			SampleBusinessObject item = container.Item as SampleBusinessObject;
			Debug.WriteLine(item.Name + " : IsChecked " + item.IsChecked
				+ " : Container IsChecked " + container.IsChecked + " : Container CheckState " + container.CheckState);
		}
	}
}
