haithambradai / gong-wpf-dragdrop

Automatically exported from code.google.com/p/gong-wpf-dragdrop
0 stars 0 forks source link

Support for TreeView #18

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
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.

Original issue reported on code.google.com by manfred....@gmail.com on 4 Jun 2010 at 1:59

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

Original comment by neilboyd on 11 Oct 2011 at 10:43

GoogleCodeExporter commented 9 years ago
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.

Original comment by neilboyd on 11 Oct 2011 at 10:55

Attachments: