I'm currently working on the implementation of Drag and Drop for a TreeView using attached properties. Long story short I would like to use an attached property to enable/disable drag and drop. I've managed to get everything working and I'm running into a really odd problem. I'm monitoring the TreeView.DragOver events to determine where in the tree I'm going to insert the new item. My problem is that when I drag to the right of the TreeViewItem's content (I.e border, or textBlock), the DragOver event is generated but the DragEventArgs.OriginalSource property is set to the Grid element of the TreeView Control. Shouldn't the Grid or the TreeViewItem generate an event?
The following is a snip it of code that ties onto the events:
/// Property Changed callback when you set DragDrop attached property
private static void OnDragDropPropertyChanged_(DependencyObject obj, DependencyPropertyChangedEventArgs args)
{
TreeView control = (TreeView)obj;
if ((bool)args.NewValue == true)
{
control.AllowDrop = true;
...
control.DragEnter += OnTreeViewDragEnter_;
control.DragLeave += OnTreeViewDragLeave_;
control.DragOver += OnTreeViewDragOver_;
control.Drop += OnTreeViewDrop_;
}
}
I've also tried to use a HitTest to determine which TreeViewItem the mouse is located over which doesn't work since DragDrop seems to stop all mouse events.
So basically I'm looking to use the entire right side of the TreeViewItem as a drop zone for the drag and drop and not only the area that hosts the content of the item. Does anyone have any suggestions?