DragDrop.Gong is an open-source library for .NET WPF applications that greatly simplifies working with Drag and Drop operations.
No matter what language you use, Drag and Drop operations are usually never as simple as they should be. Therefore, it’s common for libraries or frameworks to emerge to simplify the process.
WPF is not only no exception, but by default, drag and drop operations are a real nightmare.
DragDrop.Gong comes to solve this problem and has, in fact, become almost a standard. Personally, I wouldn’t even consider wasting time implementing Drag and Drop without this library.
With this library, we can create Drag and Drop operations easily, even with really advanced and powerful features.
Some of its features are,
- Works with any ItemsControl, such as ListBox, ListView, TreeView, or DataGrid
- Works with multiple selections
- Can insert, move, or copy an element within a collection of the same control
- Allows moving or copying elements between different controls, even if the type is different
- Compatible with MVVM architecture
- Allows displaying Adorners to give the user a visual preview of the operation
How to use DragDrop.Gong
First, we must add the NuGet package to our project via
Install-Package gong-wpf-dragdrop
Next, we add the namespace
xmlns:dd="clr-namespace:GongSolutions.Wpf.DragDrop;assembly=GongSolutions.Wpf.DragDrop"
DragDrop.Gong works by adding additional properties and behaviors to our XAML objects.
For example, with:
<ListBox ItemsSource="{Binding Collection}"
dd:DragDrop.IsDragSource="True"
dd:DragDrop.IsDropTarget="True"/>
We are saying that our ListBox can initiate Drags and receive Drops.
Of course, we can override the action to perform when starting or finishing the drop, bind whether the object is ‘draggable’ or ‘droppable’ to a property, define adorners, and any need you might have.
The library has very good documentation and includes a very large collection of examples covering a wide variety of use cases. I recommend taking a look at them, as some are quite interesting.
DragDrop.Gong is Open Source, and all the code and documentation are available at GitHub - punker76/gong-wpf-dragdrop

