Export to GitHub

gong-wpf-dragdrop - issue #18

Support for TreeView


Posted on Jun 4, 2010 by Quick Hippo

I added a feature to better support the TreeView with the drag and drop. I wanted to provide you my solution maybe you can integrate it in a future release: First I wanted that the treeview items expanded themselves when dragging over them. For this I added the following code to DropInfo.cs Line 63 TreeViewItem tvItem = item as TreeViewItem; if (tvItem != null) { tvItem.IsExpanded = true; }

Then there was a little problem with the Highlight Adorner because it Highlighted not only the treenode where the mouse was over but also all its child nodes. Found a solution but it is a bit hacky. Maybe there is a cleaner solution for this out there. I modified the method OnRender in DropTargetHighlightAdorner.cs to the following: protected override void OnRender(DrawingContext drawingContext) { if (DropInfo.VisualTargetItem != null) { Rect rect; TreeViewItem tvItem = DropInfo.VisualTargetItem as TreeViewItem; if (tvItem != null) { var grid = (Grid)((UIElement)VisualTreeHelper.GetChild(DropInfo.VisualTargetItem, 0)); var descendant = VisualTreeHelper.GetDescendantBounds(DropInfo.VisualTargetItem);

        rect = new Rect(DropInfo.VisualTargetItem.TranslatePoint(new 

Point(), AdornedElement), new Size(descendant.Width + 4, grid.RowDefinitions[0].ActualHeight)); } else { rect = new Rect(DropInfo.VisualTargetItem.TranslatePoint(new Point(), AdornedElement),

VisualTreeHelper.GetDescendantBounds(DropInfo.VisualTargetItem).Size); }

    drawingContext.DrawRoundedRectangle(null, new Pen(Brushes.Gray, 2), 

rect, 2, 2); } }

Anyway. Very nice work. Didn't found anything comparable.

Comment #1

Posted on Oct 11, 2011 by Helpful Bear

I think that expanding TreeView items when you drag over them should be configurable. This may or may not be desirable behaviour.

Comment #2

Posted on Oct 11, 2011 by Helpful Bear

Attached is a patch to expand the TreeView item when you move your mouse over it, using the code at the top of this issue, but with revision 38.

I think it needs some more work because it should only occur after a small delay, and should be configurable.

Attachments

Status: New

Labels:
Type-Defect Priority-Medium