ListBox ItemsPanel Drag and Drop weirdness #5791
Unanswered
renrutsirhc
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi all,
I'm new to Avalonia so forgive me if I've done something stupid! I've come across something weird that I can't get my head around and I'm hoping that someone can help me!
I have a ListBox bound to an ObservableCollection. In order to change the order of elements, I have a Drag and Drop implementation that uses the following kind of technique:
We get the ListBox item that the pointer is currently over. (e is DragEventArgs)
var hoveredItem = (ListBoxItem)_ListBox.GetLogicalChildren().FirstOrDefault(x => view.GetVisualsAt(e.GetPosition(view)).Contains(((IVisual)x).GetVisualChildren().First()));
and then get the index of that item to use as a position to drop the item we were dragging.
i = _ListBox.GetLogicalChildren().ToList().IndexOf(hoveredItem);
So far so good - all working as expected.
Where this gets interesting is when I try to replace the Panel of the Listbox in order to make it horizontal using the method @danwalmsley describes in #3442,
<ListBox.ItemsPanel> <ItemsPanelTemplate> <WrapPanel Orientation="Horizontal"></WrapPanel> </ItemsPanelTemplate> </ListBox.ItemsPanel>
The behaviour is different. If I drag an item to another position, all is fine and
i
is returned correctly. If I drag an item over itself,i
is returned as the last position in the ObservableCollection rather than its current position. hoveredItem however still returns the correct object.Can anyone shed any light on why this might be?
Thanks for your help!
Chris
Beta Was this translation helpful? Give feedback.
All reactions