Drag and drop Databound TreeView

Hi,

I'm trying to build a drag-and-drop feature into a treeview. The first part is working and I'm getting the item dragged from one place to another. However I need to get the item on which the dragged item was dropped.

Anyone know how to do this?

[270 byte] By [WillemM] at [2008-1-4]
# 1

As it turns out I had to use the VisualTreeHelper to hittest for the target node to drop the source node on. After that it's just moving the node in the correct way and done. Unfortunatly, WPF lacks good support for determining mouse position, so I had to use a utiltity from Josh Smith that uses Win32 calls to get the mouse position. I hope Microsoft is going to fix this in the next version.

Code Snippet

Task t = (Task)e.Data.GetData(typeof(Task));

_currentMousePosition = MouseUtilities.GetMousePosition(taskTree);
HitTestResult result = VisualTreeHelper.HitTest(taskTree, _currentMousePosition);

if (result.VisualHit is FrameworkElement)
{
_targetTask = (result.VisualHit as
FrameworkElement).DataContext as Task;
}

WillemM at 2007-10-3 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...

Visual Studio Orcas

Site Classified