This repository has been archived by the owner on Dec 21, 2023. It is now read-only.
/
MainWindow.xaml.vb
128 lines (116 loc) · 4.68 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
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
Imports DevExpress.Diagram.Core
Imports DevExpress.Xpf.Diagram
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Threading.Tasks
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Data
Imports System.Windows.Documents
Imports System.Windows.Input
Imports System.Windows.Media
Imports System.Windows.Media.Imaging
Imports System.Windows.Navigation
Imports System.Windows.Shapes
Namespace InputOutputShapes
''' <summary>
''' Interaction logic for MainWindow.xaml
''' </summary>
Partial Public Class MainWindow
Inherits Window
Public Sub New()
InitializeComponent()
InitializeStencils()
diagram.DocumentSource = "..\..\DefaultDocument.xml"
AddHandler diagram.QueryConnectionPoints, AddressOf Diagram_QueryConnectionPoints
End Sub
Private Sub InitializeStencils()
Dim myStencil As New DiagramStencil("CustomStencil", "Custom Stencil")
Dim myContainerTool As New FactoryItemTool("Decoder", Function() "Decoder", Function(d) CreateDecoderContianer())
myStencil.RegisterTool(myContainerTool)
diagram.Stencils = New DiagramStencilCollection(myStencil)
diagram.SelectedStencils = New StencilCollection(myStencil.Id)
End Sub
Private Sub Diagram_QueryConnectionPoints(ByVal sender As Object, ByVal e As DiagramQueryConnectionPointsEventArgs)
Dim shape As DiagramShape = TryCast(e.HoveredItem, DiagramShape)
If shape IsNot Nothing Then
If String.Equals(shape.Tag, "input") Then
e.ItemConnectionBorderState = ConnectionElementState.Hidden
If e.ConnectorPointType = ConnectorPointType.Begin Then
e.ItemConnectionPointStates.ToList().ForEach(Sub(cp) cp.State = ConnectionElementState.Disabled)
End If
ElseIf String.Equals(shape.Tag, "output") Then
e.ItemConnectionBorderState = ConnectionElementState.Hidden
If e.ConnectorPointType = ConnectorPointType.End Then
e.ItemConnectionPointStates.ToList().ForEach(Sub(cp) cp.State = ConnectionElementState.Disabled)
End If
End If
End If
End Sub
Public Function CreateDecoderContianer() As DiagramContainer
Dim decoderContainer As New DiagramContainer() With {
.Header = "Decoder",
.ItemsCanSelect = False,
.ItemsCanMove = False,
.DragMode = ContainerDragMode.ByAnyPoint,
.ShowHeader = True,
.CanAttachConnectorBeginPoint = False,
.CanAttachConnectorEndPoint = False,
.Width = 120,
.Height = 230
}
decoderContainer.Items.Add(CreateInputPointShape(New Point(0, 40)))
decoderContainer.Items.Add(CreateLabelShape(New Point(12, 30), "input 1", Sides.Left))
decoderContainer.Items.Add(CreateInputPointShape(New Point(0, 140)))
decoderContainer.Items.Add(CreateLabelShape(New Point(12, 130), "input 2", Sides.Left))
decoderContainer.Items.Add(CreateOutputPointShape(New Point(110, 20)))
decoderContainer.Items.Add(CreateLabelShape(New Point(60, 10), "output 1", Sides.Right))
decoderContainer.Items.Add(CreateOutputPointShape(New Point(110, 70)))
decoderContainer.Items.Add(CreateLabelShape(New Point(60, 60), "output 2", Sides.Right))
decoderContainer.Items.Add(CreateOutputPointShape(New Point(110, 120)))
decoderContainer.Items.Add(CreateLabelShape(New Point(60, 110), "output 3", Sides.Right))
decoderContainer.Items.Add(CreateOutputPointShape(New Point(110, 170)))
decoderContainer.Items.Add(CreateLabelShape(New Point(60, 160), "output 4", Sides.Right))
Return decoderContainer
End Function
Private Function CreateInputPointShape(ByVal position As Point) As DiagramShape
Return New DiagramShape() With {
.Tag = "input",
.Anchors = Sides.Left,
.Shape = BasicShapes.Ellipse,
.Position = position,
.MinWidth = 10,
.MinHeight = 10,
.ConnectionPoints = New DiagramPointCollection(New Point() { New Point(0, 0.5) }),
.Background = Brushes.Black
}
End Function
Private Function CreateOutputPointShape(ByVal position As Point) As DiagramShape
Return New DiagramShape() With {
.Tag = "output",
.Anchors = Sides.Right,
.Shape = BasicShapes.Ellipse,
.Position = position,
.MinWidth = 10,
.MinHeight = 10,
.ConnectionPoints = New DiagramPointCollection(New Point() { New Point(1, 0.5) }),
.Background = Brushes.Green
}
End Function
Private Function CreateLabelShape(ByVal position As Point, ByVal text As String, ByVal anchors As Sides) As DiagramShape
Return New DiagramShape() With {
.Content = text,
.Position = position,
.Anchors = anchors,
.StrokeThickness = 0,
.Foreground = Brushes.Black,
.Background = Brushes.Transparent,
.CanAttachConnectorBeginPoint = False,
.CanAttachConnectorEndPoint = False,
.Height = 30
}
End Function
End Class
End Namespace