using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Interactivity;
using System.Windows;
using System.Windows.Controls.Primitives;
using MECF.Framework.Common.Aitex.Core.RT.EMS;

namespace MECF.Framework.UI.Client.CenterViews.Maintain.Behavior
{
    public class SelectionChangedTargetSelectorChangingItemBehavior : Behavior<Selector>
    {
        public DataGrid Target
        {
            get { return (DataGrid)GetValue(TargetProperty); }
            set { SetValue(TargetProperty, value); }
        }

        public static readonly DependencyProperty TargetProperty =
            DependencyProperty.Register("Target", typeof(DataGrid), typeof(SelectionChangedTargetSelectorChangingItemBehavior), new PropertyMetadata(null));


        protected override void OnAttached()
        {
            AssociatedObject.SelectionChanged += SelectedOperation;
        }

        private void SelectedOperation(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems.Count == 1)
            {
                if (e.AddedItems[0] is MaintainerInfo mInfo)
                {
                    string type = mInfo.Type;
                    string name = mInfo.Name;
                    string module = mInfo.Module;
                    if (Target != null)
                    {
                        Target.ItemsSource = mInfo.MaintainerItemInfos;

                    }
                }
            };
        }

    }
}
