-
Notifications
You must be signed in to change notification settings - Fork 0
/
Helpers.cs
109 lines (97 loc) · 4.11 KB
/
Helpers.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using DevExpress.Xpf.Docking;
namespace DXDockingForLayoutPurposes {
public class Helper : DependencyObject {
public static readonly DependencyProperty DisableCrossingGroupBoundariesProperty = DependencyProperty.RegisterAttached("DisableCrossingGroupBoundaries",
typeof(bool), typeof(Helper), new PropertyMetadata(false, new PropertyChangedCallback(PropertyChanged)));
public static bool GetDisableCrossingGroupBoundaries(DependencyObject d) {
return (bool)d.GetValue(DisableCrossingGroupBoundariesProperty);
}
public static void SetDisableCrossingGroupBoundaries(DependencyObject d, bool value) {
d.SetValue(DisableCrossingGroupBoundariesProperty, value);
}
public static void PropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) {
if (!(d is LayoutGroup)) {
throw new ArgumentException("Use this attached property only with LayoutGroup");
}
}
}
public static class DragHelper {
public static bool AllowMoving(BaseLayoutItem item, BaseLayoutItem target) {
bool result = false;
if (target == null) {
return false;
}
if (DragHelper.IsItemInGroup(item) && DragHelper.IsTargetInGroup(target) && (target is LayoutControlItem)) {
return true;
}
BaseLayoutItem draggedItem = null, targetItem = null;
if (item is LayoutControlItem) {
draggedItem = item as LayoutControlItem;
if (target is LayoutControlItem) {
targetItem = target as LayoutControlItem;
if (targetItem.Parent == draggedItem.Parent) {
result = true;
}
}
if (target is LayoutGroup) {
targetItem = target as LayoutGroup;
if (targetItem.Parent == draggedItem.Parent) {
result = true;
}
}
}
if (item is LayoutGroup) {
draggedItem = item as LayoutGroup;
if (target is LayoutControlItem) {
targetItem = target as LayoutControlItem;
if (targetItem.Parent == draggedItem.Parent) {
result = true;
}
}
if (target is LayoutGroup) {
targetItem = target as LayoutGroup;
if (targetItem.Parent == draggedItem.Parent) {
result = true;
}
}
}
return result;
}
public static bool IsItemInGroup(BaseLayoutItem item) {
bool result = false;
BaseLayoutItem currentItem = item;
while (currentItem.Parent != null) {
if (currentItem.Parent is LayoutGroup) {
LayoutGroup lgroup = currentItem.Parent as LayoutGroup;
bool allowCustomization = Helper.GetDisableCrossingGroupBoundaries(lgroup);
if (allowCustomization) {
result = true;
break;
}
}
currentItem = currentItem.Parent;
}
return result;
}
public static bool IsTargetInGroup(BaseLayoutItem target) {
bool result = false;
BaseLayoutItem currentTarget = target;
while (currentTarget != null) {
if (currentTarget is LayoutGroup) {
LayoutGroup lgroup = currentTarget as LayoutGroup;
bool allowCustomization = Helper.GetDisableCrossingGroupBoundaries(lgroup);
if (allowCustomization) {
result = true;
break;
}
}
currentTarget = currentTarget.Parent;
}
return result;
}
}
}