-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.vb
68 lines (59 loc) · 3.7 KB
/
MainWindow.xaml.vb
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
Imports DevExpress.Diagram.Core
Imports DevExpress.Diagram.Core.Native
Imports DevExpress.Xpf.Diagram
Imports System.Linq
Imports System.Windows
Imports System.Windows.Media
Namespace WpfApp13
Public Class CustomDiagramContainer
Inherits DiagramContainer
Shared Sub New()
Call CanRotateProperty.OverrideMetadata(GetType(CustomDiagramContainer), New FrameworkPropertyMetadata(True, Nothing, Function(d, v) v))
End Sub
End Class
Public Partial Class MainWindow
Inherits Window
Public Sub New()
Me.InitializeComponent()
DiagramControl.ItemTypeRegistrator.Register(GetType(CustomDiagramContainer))
Me.diagramControl1.Items.Add(CreateContainerShape1())
AddHandler Me.diagramControl1.BeforeItemsRotating, AddressOf Me.DiagramControl1_BeforeItemsRotating
AddHandler Me.diagramControl1.ItemsRotating, AddressOf Me.DiagramControl1_ItemsRotating
AddHandler Loaded, AddressOf Me.MainWindow_Loaded
End Sub
Private Sub MainWindow_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
Me.diagramControl1.FitToItems(Me.diagramControl1.Items)
End Sub
Private Sub DiagramControl1_BeforeItemsRotating(ByVal sender As Object, ByVal e As DiagramBeforeItemsRotatingEventArgs)
Dim containers = e.Items.OfType(Of CustomDiagramContainer)()
For Each container In containers
e.Items.Remove(container)
For Each item In container.Items
e.Items.Add(item)
Next
Next
End Sub
Private Sub DiagramControl1_ItemsRotating(ByVal sender As Object, ByVal e As DiagramItemsRotatingEventArgs)
Dim groups = e.Items.GroupBy(Function(x) x.Item.ParentItem)
For Each group In groups
If TypeOf group.Key Is CustomDiagramContainer Then
Dim container = CType(group.Key, CustomDiagramContainer)
Dim containingRect = container.Items.[Select](Function(x) x.RotatedDiagramBounds().BoundedRect()).Aggregate(Rect.Empty, New System.Func(Of Rect, Rect, Rect)(AddressOf Rect.Union))
container.Position = New Point(containingRect.X, containingRect.Y)
container.Width = CSng(containingRect.Width)
container.Height = CSng(containingRect.Height)
End If
Next
End Sub
Public Function CreateContainerShape1() As CustomDiagramContainer
Dim container = New CustomDiagramContainer() With {.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
Dim innerShape1 = New DiagramShape() With {.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"}
Dim innerShape2 = New DiagramShape() With {.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
End Function
End Class
End Namespace