Implements WPF drag and drop functionality using DragDrop.DoDragDrop, DataObject, and drag/drop events. Use when building file drop zones, list reordering, or inter-application data transfer.
View on GitHubchristian289/dotnet-with-claudecode
wpf-dev-pack
January 23, 2026
Select agents to install to:
npx add-skill https://github.com/christian289/dotnet-with-claudecode/blob/main/wpf-dev-pack/skills/implementing-wpf-dragdrop/SKILL.md -a claude-code --skill implementing-wpf-dragdropInstallation paths:
.claude/skills/implementing-wpf-dragdrop/# WPF Drag and Drop Patterns
Implementing drag and drop functionality for data transfer within and between applications.
**Advanced Patterns:** See [ADVANCED.md](ADVANCED.md) for visual feedback, list reordering, and custom data formats.
## 1. Drag and Drop Overview
```
Drag Source Drop Target
│ │
├─ MouseDown │
├─ MouseMove (drag threshold) │
├─ DragDrop.DoDragDrop()───────────────┤
│ ├─ DragEnter
│ ├─ DragOver
│ ├─ DragLeave
│ └─ Drop
└─ GiveFeedback (cursor change)
```
---
## 2. Basic Drag Source
### 2.1 Simple Text Drag
```csharp
namespace MyApp.Views;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
public partial class DragSourceView : UserControl
{
private Point _startPoint;
private void TextBlock_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
_startPoint = e.GetPosition(null);
}
private void TextBlock_MouseMove(object sender, MouseEventArgs e)
{
if (e.LeftButton != MouseButtonState.Pressed)
return;
var currentPoint = e.GetPosition(null);
var diff = _startPoint - currentPoint;
// Check if drag threshold is exceeded
if (Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance ||
Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance)
{
if (sender is TextBlock textBlock)
{
// Create data object and start drag
var data = new DataObject(DataFormats.Text, textBlock.Text);
DragDrop.DoDragDrop(textBlock, data, DragDropEffects.Copy);
}
}
}
}
```
### 2.2 Multiple Data Formats
```csharp
private void StartDragWithMulti