You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ItemsControlExtensions.GetItemContainer finds wrong UIElement if dragging something into an empty ItemsControl that is placed INSIDE another ItemsControl
#168
Closed
haukepribnow opened this issue
Mar 1, 2016
· 1 comment
I have a situation where I have to nest ListBoxes on multiple levels and allow the user to drag and drop items between those nested boxes.
I found out that if a ListBox is empty, it seemed impossible to drag something into it. After a bit of debugging, I realized the following: When dropping my item onto a "child" ListBox (i.e. a ListBox that is nested within at least one other ListBox), the method GetItemContainer tries to find a ListBoxItem which I dropped the item on. However, since that ListBox is empty (and will therefore not contain any ListBoxItems), the method should not find any ListBoxItem. Unfortunately, because during the search it traverses the visual tree up (using GetVisualAncestor) - way beyond the empty box - it finally finds the ListBoxItem of the parentListBox in which the child ListBox actually is placed in.
The result of this is that dropped items will be placed in the wrong (in this case: always the "root") ListBox, relative to the ItemsControl. (With "root" ListBox I mean a ListBox that is not nested within another ListBox.)
A potential fix would be to try to detect if GetVisualAncestor went "too far", i.e. if the found item is actually a parent of the original itemsControl. But I'm not completely sure if that would cause anything else to break. That's why I submit this as an issue instead of adding such a fix myself and submitting a pull request. (Another pull request will follow though that should provide a first step towards fixing this.)
The text was updated successfully, but these errors were encountered:
I have a situation where I have to nest
ListBoxe
s on multiple levels and allow the user to drag and drop items between those nested boxes.I found out that if a
ListBox
is empty, it seemed impossible to drag something into it. After a bit of debugging, I realized the following: When dropping my item onto a "child"ListBox
(i.e. aListBox
that is nested within at least one otherListBox
), the methodGetItemContainer
tries to find aListBoxItem
which I dropped the item on. However, since thatListBox
is empty (and will therefore not contain anyListBoxItem
s), the method should not find anyListBoxItem
. Unfortunately, because during the search it traverses the visual tree up (usingGetVisualAncestor
) - way beyond the empty box - it finally finds theListBoxItem
of the parentListBox
in which the childListBox
actually is placed in.The result of this is that dropped items will be placed in the wrong (in this case: always the "root")
ListBox
, relative to theItemsControl
. (With "root"ListBox
I mean aListBox
that is not nested within anotherListBox
.)A potential fix would be to try to detect if
GetVisualAncestor
went "too far", i.e. if the found item is actually a parent of the originalitemsControl
. But I'm not completely sure if that would cause anything else to break. That's why I submit this as an issue instead of adding such a fix myself and submitting a pull request. (Another pull request will follow though that should provide a first step towards fixing this.)The text was updated successfully, but these errors were encountered: