Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF : Reorder WrapPanel content via drag and drop?

I am looking for a way to reorder the content (items) of a WPF WrapPanel via drag and drop. I just want to click on an item and drag it to a new position.

To my understanding this is a very common task and I wonder I someone already did this or has any idea how to implement this functionality.

I did a google search already but found nothing. Maybe it is more difficult than I expected.

like image 487
TalkingCode Avatar asked Jan 21 '10 11:01

TalkingCode


2 Answers

A wrap panel won't give you the functionality you are looking for since it is just for layout. Instead look at adding the drag and drop functionality to a ListBox and change the ItemsPanelTemplate of that ListBox to use a wrap panel.


  • Changing a list box to use a Wrap Panel
  • Library for Drag and drop (from Groky's answer)
like image 154
Martin Harris Avatar answered Oct 16 '22 15:10

Martin Harris


I've written a library which may help: default behaviour is to allow re-ordering within the same control:

http://code.google.com/p/gong-wpf-dragdrop/

Ah I notice you're talking about just a WrapPanel: you'll need to use an ItemsControl with a WrapPanel:

<ItemsControl.ItemsPanel>
    <ItemsPanelTemplate>
        <WrapPanel />
    </ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
like image 36
Grokys Avatar answered Oct 16 '22 16:10

Grokys