AvaloniaUI / Avalonia.Xaml.Behaviors

Port of Windows UWP Xaml Behaviors for Avalonia Xaml.
MIT License
385 stars 46 forks source link

Drag multiple ListBox items #117

Closed IncPlusPlus closed 6 months ago

IncPlusPlus commented 1 year ago

Discussed in https://github.com/wieslawsoltes/AvaloniaBehaviors/discussions/109

Originally posted by **IncPlusPlus** September 13, 2022 Hi there. Thanks for making such an awesome library. I was searching around trying to find out how to make an item draggable in Avalonia and almost gave up until I found this. I've figured out how to make a single `ListBox` item draggable. However, my `SelectionMode` is set to multiple so multiple items can be selected. When I select multiple items and then start to drag, all items except the one I started the drag action on get deselected. Is there a way to make dragging respect the existing selection of items in a `ListBox`? I tried removing the drag & drop behavior and discovered that this issue seems to be with Avalonia specifically. If I start making a dragging motion, the selection is cleared.

I made a discussion post a few months ago asking about this. As far as I can tell, dragging multiple items in a ListBox with SelectionMode="Multiple" is not possible. I've created this issue as an enhancement request.

Is it possible that support could be added for this scenario in the future? If not, do you know of a way I could avoid this issue? I was thinking maybe there was a way to stop the ListBoxItem from getting the PointerPressedEvent until it was followed by a PointerReleasedEvent && no drag had occurred. However, I'm not quite familiar enough with Avalonia to pull it off.