using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.ComponentModel;
using System.Collections.ObjectModel;
using Telerik.Windows.Controls.DragDrop;
using Telerik.Windows.Controls;

namespace WpfApplication16
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            radGridView.ItemsSource = new MainViewModel().Data;

            RadDragAndDropManager.AddDragQueryHandler(radGridView, OnDragQuery);

            RadDragAndDropManager.AddDropInfoHandler(radGridView, OnDragInfo);
        }

        private bool shouldUnpinPane;

        public void OnDragQuery(object sender, DragDropQueryEventArgs args)
        {
            if (args.Options.Status == DragStatus.DragQuery)
            {
                var parentPane = SamplePane;//radGridView.ParentOfType<RadPane>();
                if (parentPane != null && !parentPane.IsPinned)
                {
                    shouldUnpinPane = true;
                    parentPane.IsPinned = true;
                }
            }
        }

        public void OnDragInfo(object sender, DragDropEventArgs args)
        {
            if ((args.Options.Status == DragStatus.DropCancel || args.Options.Status == DragStatus.DropComplete) && shouldUnpinPane)
            {
                shouldUnpinPane = true;

                var parentPane = SamplePane;//radGridView.ParentOfType<RadPane>();
                if (parentPane != null)
                {
                    parentPane.IsPinned = false;
                }
            }
        }
    }


        
    public class User : INotifyPropertyChanged
    {
        private int id;

        public int Id
        {
            get
            {
                return id;
            }
            set
            {
                id = value;
                this.OnPropertyChanged("Id");
            }
        }

        private string userName;

        public string UserName
        {
            get
            {
                return userName;
            }
            set
            {
                userName = value;
                this.OnPropertyChanged("UserName");
            }
        }

        private DateTime lastLoginDate;

        public DateTime LastLoginDate
        {
            get
            {
                return lastLoginDate;
            }
            set
            {
                lastLoginDate = value;
                this.OnPropertyChanged("LastLoginDate");
            }
        }


        private bool active;

        public bool Active
        {
            get
            {
                return active;
            }
            set
            {
                active = value;
                this.OnPropertyChanged("Active");
            }
        }


        private bool approved;

        public bool Approved
        {
            get
            {
                return approved;
            }
            set
            {
                approved = value;
                this.OnPropertyChanged("Approved");
            }
        }


        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void OnPropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }

    public class MainViewModel
    {
        private ObservableCollection<User> data;

        public ObservableCollection<User> Data
        {
            get { return data; }
            set { data = value; }
        }

        public MainViewModel()
        {
            GenerateData(10);
        }

        private void GenerateData(int p)
        {
            this.data = new ObservableCollection<User>((
                from c in Enumerable.Range(0, p)
                select new User
                {
                    Id = p,
                    Active = p % 2 == 0,
                    Approved = p % 3 == 0,
                    LastLoginDate = DateTime.Now.AddDays(-p),
                    UserName = "User " + p
                }).ToList());
        }

    }
      
}
