基本的使用方法:
As promised earlier, the ListViewDragDropManager
allows you to have full-featured drag-and-drop in a ListView
with just one line of code. Here's that one line:
new ListViewDragDropManager<Foo>( this.listView );
There are a few things to point out about that one line of code. You might want to put it in a Window
's Loaded
event handling method, so that the ListView
has drag-and-drop support as soon as the Window
opens. The 'Foo
' type parameter indicates what type of objects the ListView
is displaying. The ListView
's ItemsSource
property must reference an ObservableCollection<Foo>
. Alternatively the ItemsSource
property could be bound to the DataContext
property, and have the latter reference an ObservableCollection<Foo>
.
Before going any further into how to use the ListViewDragDropManager
, let's take a look at its public properties:
DragAdornerOpacity
- Get
s/set
s the opacity of the drag adorner. This property has no effect if ShowDragAdorner
is false
. The default value is 0.7
IsDragInProgress
- Returns true
if there is currently a drag operation being managed.
ListView
- Get
s/set
s the ListView
whose dragging is managed. This property can be set to null
, to prevent drag management from occurring. If the ListView
's AllowDrop
property is false
, it will be set to true
.
ShowDragAdorner
- Get
s/set
s whether a visual representation of the ListViewItem
being dragged follows the mouse cursor during a drag operation. The default value is true
.
There is also one event exposed:
ProcessDrop
- Raised when a drop occurs. By default the dropped item will be moved to the target index. Handle this event if relocating the dropped item requires custom behavior. Note, if this event is handled the default item dropping logic will not occur.