using com.superscene.ui;
using parkMonitor.viewModel.objectTree;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace parkMonitor.view {
	public interface ISelectProperty {
		bool IsSelected { get; set; }
	}

	/// <summary>item选择Behavior</summary>
	public class ItemsControlSelectBehavior : BaseBehavior<FrameworkElement> {
		public override void onAttached() {
			base.onAttached();
			if(element == null) {
				return;
			}

			//Debug.WriteLine("aa");
			element.GotFocus += Element_GotFocus;
		}

		private void Element_GotFocus(object sender, RoutedEventArgs e) {
			//if(TreeView != null) {
			//	//TreeViewItem item;item.IsSelected
			//	//TreeView.SelectedItem = element.DataContext;
			//}
			//if(e.Source != element) {
			//	return;
			//}
			ISelectProperty item = element.DataContext as ISelectProperty;
			if(item == null) {
				return;
			}
			item.IsSelected = true;
		}

		public override void onDetaching() {
			base.onDetaching();
			if(element == null) {
				return;
			}

			//Debug.WriteLine("cc");
			element.GotFocus -= Element_GotFocus;
		}

	}
}
