0

I'm trying to figure out how to reorder the listbox without any code behind. I tried following this post: WPF C#: Rearrange items in listbox via drag and drop It definitely works, but I want to do it with ICommand or AttachBehavior.

Any suggestion? How to hook the Drop and PreviewMouseLeftButtonDownEvent with AttachBehavior?

The Listbox's ItemsSource is a Observable Collection.

Elaine Chen
  • 177
  • 1
  • 13

1 Answers1

0

Check out this CodeProject article. This implementation rely on two attached properties DragEnabled and DropEnabled.

<ListBox lib:DragAndDrop.DragEnabled="true"/> // Source
<ListBox lib:DragAndDrop.DropEnabled="true"/> // Target
dontbyteme
  • 1,221
  • 1
  • 11
  • 23
  • It's not quite what I'm looking for. I want to reorder the items within one listbox. And this project is dragging item from one listbox to another. – Elaine Chen Sep 06 '18 at 16:03
  • Do you have any other example without finding ancestor? – Elaine Chen Sep 06 '18 at 16:20
  • If you can also use a ListView then this [CodeProject](https://www.codeproject.com/Articles/17266/Drag-and-Drop-Items-in-a-WPF-ListView) articel may help you. This is what I'm using for drag and drop ordering in a ListView. A combination of both is probably what you're searching for. – dontbyteme Sep 07 '18 at 05:07