Using the example tree above, my overall goal is to only allow nodes to be dropped within their own parent node, or essentially to be re-arranged with the node's siblings. (For example: If the user is dragging node C1, it is only to be able to be dropped BEFORE C3 or AFTER C3, no where else or in any other nodes period. Likewise, if dragging node A2, it is only to be able to be dropped BEFORE A1)
I discovered how to accomplish this by handling the PreviewDragEnded event and determining the level of the targetItem and setting eventArgs.Handled = true if the drop is invalid. I am not real high on this solution though as it appears to the user that they are able to drop the node somewhere and then nothing happens.
Instead, I would like to do something like handle the PreviewDragStarted event, Set 'IsDropAllowed = false' for all nodes of the tree, then determine the parent of the node being dragged and set 'IsDropAllowed = true' for that parent node. This way the user see's the 'stop sign, not allowed icon' for all other droppable places except within the node's parent node. (at the same level as the node being dragged) So the user knows before dropping the node that the only place it can be dropped is at it's current level of the tree.
I have spent a few hours attempting this and have constructed a simple test project that has a tree view bound to an ObservableCollection in a view model that matches the above structure. I have the PreviewDragStarted Handler rigged up to set 'IsDropAllowed = false' for all nodes of the tree, and then set 'IsDropAllowed = true' for the node being dragged's parent node. This appears to be working, as far as showing the stop sign correctly.
My problem is...
A) I cannot figure out how to set 'IsDropAllowed = false' for the Root's container. (I do this for all other nodes of the tree by getting the RadTreeViewItem of the bound item and setting the property to false. Is there a way to get a container like 'RadTreeViewItem' for the root node and set the 'IsDropAllowed' to false?) Essentially, using the above example, when dragging node C1, I can correctly only drop it within node C, but I can also drop it BEFORE/AFTER node A, BEFORE node B, AFTER node D. This is the problem.
B) When dragging a node, it makes a duplicate node at the drop location and doesnt remove the original node, any idea why this could be happening? the only thing I am doing is setting 'IsDropAllowed' property in this PreviewDragStart handler...
Thanks a bunch for any help that can be provided!