This repository has been archived by the owner on Oct 16, 2023. It is now read-only.
/
ModalHelper.vb
137 lines (119 loc) · 6.32 KB
/
ModalHelper.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
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Threading.Tasks
Imports System.Windows
Imports DevExpress.Xpf.Docking
Imports DevExpress.Xpf.Docking.Base
Namespace Example
Public Class BaseLayoutItemState
Public Property AllowActivate() As Boolean
Public Property AllowClose() As Boolean
Public Property AllowDock() As Boolean
Public Property AllowDrag() As Boolean
Public Property AllowDrop() As Boolean
Public Property AllowFloat() As Boolean
Public Property AllowHide() As Boolean
Public Property AllowMinimize() As Boolean
Public Property AllowMaximize() As Boolean
Public Property AllowMove() As Boolean
Public Property AllowRestore() As Boolean
Public Property AllowSelection() As Boolean
Public Property AllowSizing() As Boolean
Public Property Focusable() As Boolean
Public Property IsEnabled() As Boolean
End Class
Public Class ModalHelper
Public Shared IsModalProperty As DependencyProperty = DependencyProperty.RegisterAttached("IsModal", GetType(Boolean), GetType(ModalHelper), New PropertyMetadata(False, New PropertyChangedCallback(AddressOf IsModalChanged)))
Public Shared WindowStateProperty As DependencyProperty = DependencyProperty.RegisterAttached("WindowState", GetType(BaseLayoutItemState), GetType(ModalHelper))
Public Shared Function GetIsModal(ByVal d As DependencyObject) As Boolean
Return DirectCast(d.GetValue(IsModalProperty), Boolean)
End Function
Public Shared Sub SetIsModal(ByVal d As DependencyObject, ByVal value As Boolean)
d.SetValue(IsModalProperty, value)
End Sub
Private Shared Sub IsModalChanged(ByVal d As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
Dim item As BaseLayoutItem = TryCast(d, BaseLayoutItem)
If d IsNot Nothing Then
SetIsModal(item, DirectCast(e.NewValue, Boolean))
If DirectCast(e.NewValue, Boolean) Then
CreateStates(item)
LockWindows(item)
AddHandler item.GetDockLayoutManager().DockItemClosing, AddressOf ModalHelper_DockItemClosing
Else
UnlockWindows(item)
RemoveHandler item.GetDockLayoutManager().DockItemClosing, AddressOf ModalHelper_DockItemClosing
End If
End If
End Sub
Private Shared Sub ModalHelper_DockItemClosing(ByVal sender As Object, ByVal e As ItemCancelEventArgs)
SetIsModal(e.Item, False)
End Sub
Public Shared Function GetWindowState(ByVal d As DependencyObject) As BaseLayoutItemState
Return DirectCast(d.GetValue(WindowStateProperty), BaseLayoutItemState)
End Function
Public Shared Sub SetWindowState(ByVal d As DependencyObject, ByVal value As BaseLayoutItemState)
d.SetValue(WindowStateProperty, value)
End Sub
Private Shared Sub UnlockWindows(ByVal window As BaseLayoutItem)
If window.Parent IsNot Nothing Then
For Each item In window.Parent.Items
Dim state As BaseLayoutItemState = GetWindowState(item)
If state IsNot Nothing Then
item.AllowActivate = state.AllowActivate
item.AllowClose = state.AllowClose
item.AllowDock = state.AllowDock
item.AllowDrag = state.AllowDrag
item.AllowDrop = state.AllowDrop
item.AllowFloat = state.AllowFloat
item.AllowHide = state.AllowHide
item.AllowMaximize = state.AllowMaximize
item.AllowMinimize = state.AllowMinimize
item.AllowMove = state.AllowMove
item.AllowRestore = state.AllowRestore
item.AllowSelection = state.AllowSelection
item.AllowSizing = state.AllowSizing
item.Focusable = state.Focusable
item.IsEnabled = state.IsEnabled
state = Nothing
End If
Next item
End If
End Sub
Private Shared Sub LockWindows(ByVal window As BaseLayoutItem)
If window.Parent IsNot Nothing Then
For Each item In window.Parent.Items
If Not GetIsModal(item) Then
item.AllowActivate = False
item.AllowClose = False
item.AllowDock = False
item.AllowDrag = False
item.AllowDrop = False
item.AllowFloat = False
item.AllowHide = False
item.AllowMaximize = False
item.AllowMinimize = False
item.AllowMove = False
item.AllowRestore = False
item.AllowSelection = False
item.AllowSizing = False
item.Focusable = False
item.IsEnabled = False
End If
Next item
End If
End Sub
Private Shared Sub CreateWindowState(ByVal window As BaseLayoutItem)
Dim state As New BaseLayoutItemState() With {.AllowActivate = window.AllowActivate, .AllowClose = window.AllowClose, .AllowDock = window.AllowDock, .AllowDrag = window.AllowDrag, .AllowDrop = window.AllowDrop, .AllowFloat = window.AllowFloat, .AllowHide = window.AllowHide, .AllowMaximize = window.AllowMaximize, .AllowMinimize = window.AllowMinimize, .AllowMove = window.AllowMove, .AllowRestore = window.AllowRestore, .AllowSelection = window.AllowSelection, .AllowSizing = window.AllowSizing, .Focusable = window.Focusable, .IsEnabled = window.IsEnabled}
SetWindowState(window, state)
End Sub
Private Shared Sub CreateStates(ByVal window As BaseLayoutItem)
If window.Parent IsNot Nothing Then
For Each item In window.Parent.Items
CreateWindowState(item)
Next item
End If
End Sub
End Class
End Namespace