dev301

Hi.
I'm currently playing around a little with drag and drop in TreeViews, and poking all sorts of options for their display.
The code I'm basing myself on is Josh Smith's ListViewDragDropManager, and just converted it to manage treeviews, with almost all of the same code. The logics are all exactly the same, and the display is also from another project I saw recently.

What I came across is just very weird:
when I expand a TreeViewItem, then collapse it, the TreeViewItem thinks it's still expanded.
all of the DragOver events come from the incorrect treeviewitem, which is ofcourse very bad.

The best way to understand what I'm saying is to look at this test project, and do the following:
1. drag the first item around a little, see that you get all the normal behavior.
2. expand the first item.
3. collapse the first item.
4. try the drag operations again. notice how when you pass over items from the second row,
the mouse thinks it's over the first row treeviewitem.

solution is here(zip) : http://www22.brinkster.com/betzera/ohev/dev301/treeview%20dragger.zip



Re: Windows Presentation Foundation (WPF) Wrong events jumping in TreeView

dev301

tried InvalidiateVisual, Arrage, Measure etc. on the reeview and the collapsing/expanding item, nothing seems to do anything.



Re: Windows Presentation Foundation (WPF) Wrong events jumping in TreeView

dev301

Is there anything more 'powerful' than InvalidteXXXs

I even tried visibility switch, but nothing seems to change.

If theres anything wrong with the actual code that's causing this, or if anyone has the slightest clue - It's really appriciated.

thanks.





Re: Windows Presentation Foundation (WPF) Wrong events jumping in TreeView

Yi-Lun Luo - MSFT

Hello, looks like after you expanded and collapsed an item and drag it, when dropped on the item below, the IndexUnderDragCursor will return the dragged item itself. However, when debugging, I found in the IsMouseOver method, the Rectangle returned by VisualTreeHelper.GetDescendantBounds seems to be right. It’s about 200 when the item is expanded and about 30 when it’s collapsed. So I don’t think the problem is the TreeViewItem thinks it’s still expanded even if it’s collapsed. Anyway, I found that if you modify the IndexUnderDragCursor method, change break to continue, it seems to work.

int IndexUnderDragCursor

{

get

{

int index = -1;

for (int i = 0; i < this.treeView.Items.Count; ++i)

{

TreeViewItem item = this.GetTreeViewItem(i);

if (this.IsMouseOver(item))

{

index = i;

continue;

}

}

return index;

}

}

Sorry don’t have time to find out the real problem. But you can try this trick.






Re: Windows Presentation Foundation (WPF) Wrong events jumping in TreeView

dev301

this helps as a patch, thank you.
I tried running in reverse (i = count, --i), same result.
but the problem still remains that the wrong treeview item raises "DragOver", meaning the
"drop here" colors are messed up, and even when I can go around it, it seems like a pretty serious bug (if not in the code, in the framework).