-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
104 lines (90 loc) · 4 KB
/
MainWindow.xaml.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
using DevExpress.Diagram.Core;
using DevExpress.Diagram.Core.Native;
using DevExpress.Xpf.Diagram;
using System.Linq;
using System.Windows;
using System.Windows.Media;
namespace WpfApp13 {
public class CustomDiagramContainer : DiagramContainer {
static CustomDiagramContainer() {
CanRotateProperty.OverrideMetadata(typeof(CustomDiagramContainer), new FrameworkPropertyMetadata(true, null, (d, v) => v));
}
}
public partial class MainWindow : Window {
public MainWindow() {
InitializeComponent();
DiagramControl.ItemTypeRegistrator.Register(typeof(CustomDiagramContainer));
diagramControl1.Items.Add(CreateContainerShape1());
diagramControl1.BeforeItemsRotating += DiagramControl1_BeforeItemsRotating;
diagramControl1.ItemsRotating += DiagramControl1_ItemsRotating;
this.Loaded += MainWindow_Loaded;
}
private void MainWindow_Loaded(object sender, RoutedEventArgs e) {
diagramControl1.FitToItems(diagramControl1.Items);
}
private void DiagramControl1_BeforeItemsRotating(object sender, DiagramBeforeItemsRotatingEventArgs e) {
var containers = e.Items.OfType<CustomDiagramContainer>();
foreach (var container in containers) {
e.Items.Remove(container);
foreach (var item in container.Items)
e.Items.Add(item);
}
}
private void DiagramControl1_ItemsRotating(object sender, DiagramItemsRotatingEventArgs e) {
var groups = e.Items.GroupBy(x => x.Item.ParentItem);
foreach (var group in groups) {
if (group.Key is CustomDiagramContainer) {
var container = (CustomDiagramContainer)group.Key;
var containingRect = container.Items.Select(x => x.RotatedDiagramBounds().BoundedRect()).Aggregate(Rect.Empty, Rect.Union);
container.Position = new Point(containingRect.X, containingRect.Y);
container.Width = (float)containingRect.Width;
container.Height = (float)containingRect.Height;
}
}
}
public CustomDiagramContainer CreateContainerShape1() {
var container = new CustomDiagramContainer() {
Width = 200,
Height = 200,
Position = new Point(100, 100),
CanAddItems = false,
ItemsCanChangeParent = false,
ItemsCanCopyWithoutParent = false,
ItemsCanDeleteWithoutParent = false,
ItemsCanAttachConnectorBeginPoint = false,
ItemsCanAttachConnectorEndPoint = false
};
container.StrokeThickness = 0;
container.Background = Brushes.Transparent;
var innerShape1 = new DiagramShape() {
CanSelect = true,
CanChangeParent = false,
CanEdit = true,
CanResize = false,
CanRotate = false,
CanCopyWithoutParent = false,
CanDeleteWithoutParent = false,
CanMove = false,
Shape = BasicShapes.Trapezoid,
Height = 50,
Width = 200,
Content = "Custom text"
};
var innerShape2 = new DiagramShape() {
CanSelect = false,
CanChangeParent = false,
CanEdit = false,
CanCopyWithoutParent = false,
CanDeleteWithoutParent = false,
CanMove = false,
Shape = BasicShapes.Rectangle,
Height = 150,
Width = 200,
Position = new Point(0, 50),
};
container.Items.Add(innerShape1);
container.Items.Add(innerShape2);
return container;
}
}
}