Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Highlight adorner not outlining everything #97

Closed
dmrickey opened this issue Apr 1, 2014 · 5 comments
Closed

Highlight adorner not outlining everything #97

dmrickey opened this issue Apr 1, 2014 · 5 comments
Milestone

Comments

@dmrickey
Copy link

dmrickey commented Apr 1, 2014

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);
        }
    }
@dmrickey
Copy link
Author

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

@dmrickey
Copy link
Author

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.

@punker76
Copy link
Owner

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

@dmrickey
Copy link
Author

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.

@dmrickey
Copy link
Author

Ok, pull request submitted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants