-
Notifications
You must be signed in to change notification settings - Fork 1
/
CustomTextDragSource.cs
33 lines (30 loc) · 1.05 KB
/
CustomTextDragSource.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using GongSolutions.Wpf.DragDrop;
namespace DragHandlerSample
{
public class CustomTextDragSource : DefaultDragHandler
{
public override bool CanStartDrag(IDragInfo dragInfo)
{
// Check that the control which started the drag is a label.
// Can be changed to the desired control type
return (dragInfo.VisualSource is Label);
}
public override void StartDrag(IDragInfo dragInfo)
{
// Get the control that started the drag
Label sourceControl = dragInfo.VisualSource as Label;
if (sourceControl == null)
return;
// Drag the content of the label as text
dragInfo.DataFormat = DataFormats.GetDataFormat(DataFormats.Text);
dragInfo.Data = sourceControl.Content;
dragInfo.Effects = DragDropEffects.Copy;
}
}
}