-
Notifications
You must be signed in to change notification settings - Fork 3
/
ListDropTarget.cs
63 lines (60 loc) · 1.74 KB
/
ListDropTarget.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using GongSolutions.Wpf.DragDrop;
using System;
using System.Collections;
using System.Dynamic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Markup;
using Newtonsoft.Json.Linq;
namespace WPF_dnscrypt_proxy_md
{
public class ListDropTarget : MarkupExtension, IDropTarget
{
public void DragOver(IDropInfo dropInfo)
{
if(dropInfo.Data is IEnumerable data)
{
foreach(dynamic item in data)
{
if (null == item.STAMP)
{
dropInfo.NotHandled = false;
break;
}
dropInfo.NotHandled = true;
}
}
else
{
dynamic item = dropInfo.Data;
dropInfo.NotHandled = !(item is DataObject) && null != item.STAMP;
}
}
public void Drop(IDropInfo dropInfo)
{
var ic = dropInfo.TargetCollection as ItemCollection;
void Add (dynamic item) {
dynamic eo = new ExpandoObject();
eo.Name = item.Name;
eo.STAMP = (item.STAMP as JToken).DeepClone();
ic.Add(eo);
};
if (dropInfo.Data is IEnumerable data)
{
foreach (dynamic item in data)
{
Add(item);
}
}
else
{
Add(dropInfo.Data);
}
((MainWindow)App.Current.MainWindow).ValidateListViewItems();
}
public override object ProvideValue(IServiceProvider serviceProvider)
{
return this;
}
}
}