Hi Telerik,
I have a user control with a RadTreeView which is open in multiple docking panes.
The user can drag nodes, between the trees of the floating panes.
Since I reuse the usercontrol with the RadTreeView, when doing a drag and drop the same PreviewDragEnded event handler is called for both the source tree & target tree.
First the PreviewDragEnded event of the source tree from which the node is being dragged is called.
Next the PreviewDragEnded event of the target tree onto which the item is being dropped is called.
I have some questions in the code below:
Please keep in mind that I need to know also the DropPosition, and Item onto which is being dropped.
Also, I can't use the default behavior of RadTreeView since I need to call Add/Remove methods on my viewmodel explicitly that do more processing than just adding/removing to a collection.
Also I am required to allow the user to re-order chapters using drag & drop, in the RadTreeView.
How can I detect when I'm in a self-drag & drop scenario?
One thought, crossing my mind was using sourceTree != e.TargetDropItem.ParentTree, but the problem is that, if I drop at the end of a tree, then e.TargetDropItem is null.
I have a user control with a RadTreeView which is open in multiple docking panes.
The user can drag nodes, between the trees of the floating panes.
Since I reuse the usercontrol with the RadTreeView, when doing a drag and drop the same PreviewDragEnded event handler is called for both the source tree & target tree.
First the PreviewDragEnded event of the source tree from which the node is being dragged is called.
Next the PreviewDragEnded event of the target tree onto which the item is being dropped is called.
I have some questions in the code below:
//How do I know that this is the event of the source tree from which the item is dragged,
and remove the item from the viewmodel (datacontext) items?
//How do I know that this is the event of the target tree in which the item is dropped and
add the item to the view model (datacontext)?
//How can I get a reference to
both
source tree datacontext, target tree datacontext in here,
so I can call Remove, Add methods on them?
Please keep in mind that I need to know also the DropPosition, and Item onto which is being dropped.
Also, I can't use the default behavior of RadTreeView since I need to call Add/Remove methods on my viewmodel explicitly that do more processing than just adding/removing to a collection.
Also I am required to allow the user to re-order chapters using drag & drop, in the RadTreeView.
How can I detect when I'm in a self-drag & drop scenario?
One thought, crossing my mind was using sourceTree != e.TargetDropItem.ParentTree, but the problem is that, if I drop at the end of a tree, then e.TargetDropItem is null.
private void chaptersTree_PreviewDragEnded(object sender, RadTreeViewDragEndedEventArgs e)
{
//Get the RadTreeView
RadTreeView sourceTree = e.OriginalSource as RadTreeView;
//Get the dragged DataItem
Chapter draggedDataItem = e.DraggedItems[
0
] as Chapter;
RadTreeViewItem destinationItem = e.TargetDropItem;
//How do I know that this is the event of the source tree from which the item is dragged, and remove the item from the viewmodel items?
//How do I know that this is the event of the target tree in which the item is dropped?
//How can I get a reference to
both
source tree datacontext, target tree datacontext in here, so I can call Remove, Add methods on them?
e.Handled = true;
}