using System.Windows.Controls;
using Telerik.Windows.Controls.DragDrop;
using Telerik.Windows;
using Telerik.Windows.Controls;
using System;

namespace Drop_ForbidAllow
{
	public partial class MainPage : UserControl
	{
		private SampleViewModel sampleVM;
		public MainPage()
		{
			InitializeComponent();
			sampleVM = new SampleViewModel();
			SampleTreeView.DataContext = sampleVM;
			
			//Set the "handlesToo" to "true" in order to get the handeled routed events.
			SampleTreeView.AddHandler(RadDragAndDropManager.DropQueryEvent, 
									new EventHandler<DragDropQueryEventArgs>(OnDropQuery), true);
		}

		private void OnDropQuery(object sender, DragDropQueryEventArgs e)
		{
			RadTreeViewItem item = e.OriginalSource as RadTreeViewItem;
			if (item != null)
			{
				Measure measure = item.Item as Measure;
				if (measure != null)
				{
					//Set the query result in order to determine is the drop allowed over the corresponding item or not.
					e.QueryResult = measure.IsDraggable;
				}
			}
		}
	}
}
