punker76 / gong-wpf-dragdrop

The GongSolutions.WPF.DragDrop library is a drag'n'drop framework for WPF

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Highlight adorner not outlining everything

dmrickey opened this issue · comments

Upgrading from 1.3 to current is changing the behavior to outline only the root element and not its children. I know in 1.3 it was broken so that it would highlight any space that tree item had taken up (as in it highlighted too much if the item was expanded then collapsed then highlighted).

Insight on if this is the expected behavior would be appreciated.

image

from DropTargetHighlightAdorner there is this. It looks like the problem is that rect is never empty so it never uses the height that I'm seeing on the screen.

    protected override void OnRender(DrawingContext drawingContext)
    {
        var visualTargetItem = this.DropInfo.VisualTargetItem;
        if (visualTargetItem != null) {
            var rect = Rect.Empty;

            var tvItem = visualTargetItem as TreeViewItem;
            if (tvItem != null && VisualTreeHelper.GetChildrenCount(tvItem) > 0) {
                var grid = VisualTreeHelper.GetChild(tvItem, 0) as Grid;
                if (grid != null) {
                    var descendant = VisualTreeHelper.GetDescendantBounds(tvItem);
                    rect = new Rect(tvItem.TranslatePoint(new Point(), this.AdornedElement), new Size(descendant.Width + 4, grid.RowDefinitions[0].ActualHeight));
                }
            }
            if (rect.IsEmpty) {
                rect = new Rect(visualTargetItem.TranslatePoint(new Point(), this.AdornedElement), VisualTreeHelper.GetDescendantBounds(visualTargetItem).Size);
            }
            drawingContext.DrawRoundedRectangle(null, new Pen(Brushes.Gray, 2), rect, 2, 2);
        }
    }

I've since reverted back to a previous version as I'd rather have it highlight too much than not enough.

I was encountering a bug that's already been fixed (the context menu was locking out most of the controls after it had been closed under certain conditions), so I downloaded the source and fixed the above issue for myself. Replace the line "if (rect.IsEmpty)" with "if (tvItem.IsExpanded)" and I was able to get the expected result.

@claudekennilol you can make a pr to solve this for me and all other. :-D

I just realized it needs a bit more work than what I pointed out above. If the tree is more than two elements deep.. For example, if I have root -> branch -> leaf and expand all three, but then collapse only the leaf, then that gives me the previous behavior where if I highlight the root that is expanded then it highlights too much. So I'll take a look into it and see if I can figure out a solution that works in all cases.

Ok, pull request submitted.