This repository has been archived by the owner on Oct 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.vb
224 lines (217 loc) · 8.61 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
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
Imports DevExpress.Xpf.Docking
Imports System.Collections.ObjectModel
Namespace Q357154
''' <summary>
''' Interaction logic for MainWindow.xaml
''' </summary>
Partial Public Class MainWindow
Inherits Window
Public Sub New()
InitializeComponent()
AddHandler dockManager.Loaded, AddressOf dockManager_Loaded
End Sub
Private Sub dockManager_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
For Each item As BaseLayoutItem In dockManager.GetItems()
widths(item) = item.ItemWidth
heights(item) = item.ItemHeight
Next item
End Sub
Private Sub DoAnimation()
If dockManager Is Nothing Then
Return
End If
For Each item As BaseLayoutItem In dockManager.GetItems()
If item Is dockManager.LayoutRoot Then
Continue For
End If
Animate(item)
Next item
End Sub
Private maximizedItem As BaseLayoutItem
Private widths As New Dictionary(Of BaseLayoutItem, GridLength)()
Private heights As New Dictionary(Of BaseLayoutItem, GridLength)()
Private Sub Animate(ByVal layoutItem As BaseLayoutItem)
BeginAnimationToFixedValue(layoutItem, widths(layoutItem), BaseLayoutItem.ItemWidthProperty)
BeginAnimationToFixedValue(layoutItem, heights(layoutItem), BaseLayoutItem.ItemHeightProperty)
End Sub
Private Sub BeginAnimationToFixedValue(ByVal layoutItem As BaseLayoutItem, ByVal l As GridLength, ByVal prop As DependencyProperty)
Dim a As GridLengthAnimation = CreateAnimation(layoutItem, prop, l)
AddHandler a.Completed, Function(s, e) AnonymousMethod1(s, e, layoutItem, prop, a)
layoutItem.BeginAnimation(prop, a)
End Sub
Private Function AnonymousMethod1(ByVal s As Object, ByVal e As Object, ByVal layoutItem As BaseLayoutItem, ByVal prop As DependencyProperty, ByVal a As GridLengthAnimation) As Boolean
layoutItem.SetValue(prop, a.To)
Return True
End Function
Private Function CreateAnimation(ByVal item As BaseLayoutItem, ByVal [property] As DependencyProperty, ByVal value As GridLength) As GridLengthAnimation
Dim [to] As New GridLength(0, GridUnitType.Star)
If maximizedItem IsNot Nothing Then
If maximizedItem Is item OrElse maximizedItem.Parent Is item Then
[to] = value
End If
Else
[to] = value
End If
Dim a As GridLengthAnimation = New GridLengthAnimation With {.From = CType(item.GetValue([property]), GridLength), .To = [to], .Duration = New TimeSpan(0, 0, 0, 0, 500), .FillBehavior = System.Windows.Media.Animation.FillBehavior.Stop}
Return a
End Function
Private Sub OnPanelContentControlBackButtonClicked(ByVal sender As Object, ByVal e As EventArgs)
maximizedItem = Nothing
DoAnimation()
CType(sender, PanelContentControl).IsExpanded = False
End Sub
Private Sub OnPanelContentControlMouseLeftButtonDown(ByVal sender As Object, ByVal e As MouseButtonEventArgs)
maximizedItem = DockLayoutManager.GetLayoutItem(TryCast(sender, DependencyObject))
DoAnimation()
CType(sender, PanelContentControl).IsExpanded = True
End Sub
End Class
Public Class PanelContentControl
Inherits ContentControl
#Region "static"
Public Shared ReadOnly IndexNameProperty As DependencyProperty
Public Shared ReadOnly CurrentChangeProperty As DependencyProperty
Public Shared ReadOnly CurrentValueProperty As DependencyProperty
Public Shared ReadOnly IsChangePositiveProperty As DependencyProperty
Public Shared ReadOnly IsExpandedProperty As DependencyProperty
Shared Sub New()
IndexNameProperty = DependencyProperty.Register("IndexName", GetType(String), GetType(PanelContentControl))
CurrentChangeProperty = DependencyProperty.Register("CurrentChange", GetType(Double), GetType(PanelContentControl), New PropertyMetadata(0.0, AddressOf OnCurrentChangeChanged))
CurrentValueProperty = DependencyProperty.Register("CurrentValue", GetType(Double), GetType(PanelContentControl), New PropertyMetadata(0.0))
IsChangePositiveProperty = DependencyProperty.Register("IsChangePositive", GetType(Boolean?), GetType(PanelContentControl), New PropertyMetadata(Nothing, AddressOf OnIsChangePositiveChanged))
IsExpandedProperty = DependencyProperty.Register("IsExpanded", GetType(Boolean), GetType(PanelContentControl), New PropertyMetadata(False, AddressOf OnIsExpandedChanged))
End Sub
Private Shared Sub OnCurrentChangeChanged(ByVal d As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
Dim panelContentControl As PanelContentControl = CType(d, PanelContentControl)
panelContentControl.IsChangePositive = If(CDbl(e.NewValue) = 0, Nothing, CType(CDbl(e.NewValue) > 0, Boolean?))
End Sub
Private Shared Sub OnIsChangePositiveChanged(ByVal d As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
CType(d, PanelContentControl).UpdateVisualState()
End Sub
Private Shared Sub OnIsExpandedChanged(ByVal d As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
CType(d, PanelContentControl).UpdateVisualState()
End Sub
#End Region
Public Sub New()
DefaultStyleKey = GetType(PanelContentControl)
Background = Brushes.Transparent
AddHandler Unloaded, AddressOf PanelContentControl_Unloaded
AddHandler SizeChanged, AddressOf PanelContentControl_SizeChanged
Cursor = Cursors.Hand
End Sub
Private Sub PanelContentControl_Unloaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
If PartBackButton IsNot Nothing Then
RemoveHandler PartBackButton.Click, AddressOf PartBackButton_Click
End If
End Sub
Private Sub PanelContentControl_SizeChanged(ByVal sender As Object, ByVal e As SizeChangedEventArgs)
UpdateVisualState()
End Sub
Public Event BackButtonClicked As EventHandler
Protected Sub RaiseBackButtonClicked()
RaiseEvent BackButtonClicked(Me, EventArgs.Empty)
End Sub
Private PartBackButton As Button
Public Overrides Sub OnApplyTemplate()
MyBase.OnApplyTemplate()
UpdateVisualState()
PartBackButton = TryCast(GetTemplateChild("PART_BackButton"), Button)
If PartBackButton IsNot Nothing Then
AddHandler PartBackButton.Click, AddressOf PartBackButton_Click
End If
End Sub
Private Sub PartBackButton_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
RaiseBackButtonClicked()
End Sub
Protected Overrides Sub OnMouseEnter(ByVal e As MouseEventArgs)
MyBase.OnMouseEnter(e)
UpdateVisualState()
End Sub
Protected Overrides Sub OnMouseLeave(ByVal e As MouseEventArgs)
MyBase.OnMouseEnter(e)
UpdateVisualState()
End Sub
Private Sub UpdateVisualState()
If IsMouseOver Then
VisualStateManager.GoToState(Me, "MouseOver", True)
Else
VisualStateManager.GoToState(Me, "Normal", True)
End If
If IsChangePositive Is Nothing Then
VisualStateManager.GoToState(Me, "Zero", False)
End If
If IsChangePositive = True Then
VisualStateManager.GoToState(Me, "Positive", False)
End If
If IsChangePositive = False Then
VisualStateManager.GoToState(Me, "Negative", False)
End If
If IsExpanded Then
Cursor = Cursors.Arrow
VisualStateManager.GoToState(Me, "Checked", False)
Else
Cursor = Cursors.Hand
VisualStateManager.GoToState(Me, "Unchecked", False)
End If
If RenderSize.Width < 165 Then
VisualStateManager.GoToState(Me, "CompactView", False)
Else
VisualStateManager.GoToState(Me, "AdvancedView", False)
End If
End Sub
Public Property IndexName() As String
Get
Return CStr(GetValue(IndexNameProperty))
End Get
Set(ByVal value As String)
SetValue(IndexNameProperty, value)
End Set
End Property
Public Property CurrentChange() As Double
Get
Return CDbl(GetValue(CurrentChangeProperty))
End Get
Set(ByVal value As Double)
SetValue(CurrentChangeProperty, value)
End Set
End Property
Public Property CurrentValue() As Double
Get
Return CDbl(GetValue(CurrentValueProperty))
End Get
Set(ByVal value As Double)
SetValue(CurrentValueProperty, value)
End Set
End Property
Public Property IsChangePositive() As Boolean?
Get
Return CType(GetValue(IsChangePositiveProperty), Boolean?)
End Get
Set(ByVal value? As Boolean)
SetValue(IsChangePositiveProperty, value)
End Set
End Property
Public Property IsExpanded() As Boolean
Get
Return CBool(GetValue(IsExpandedProperty))
End Get
Set(ByVal value As Boolean)
SetValue(IsExpandedProperty, value)
End Set
End Property
End Class
End Namespace