-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainViewModel.vb
More file actions
103 lines (80 loc) · 3.6 KB
/
MainViewModel.vb
File metadata and controls
103 lines (80 loc) · 3.6 KB
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
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports DevExpress.Mvvm.POCO
Namespace AppearanceCustomization
Public Class MainViewModel
Private random As Random
Public Sub New()
random = New Random()
Items = CreateTestItems()
SelectedItem = Items(0).Nodes(0)
End Sub
Public Property Items As List(Of Node)
Public Overridable Property SelectedItem As Node
Public Function CreateTestItems() As List(Of Node)
Dim result = New List(Of Node)()
result.Add(Node.Create("Item 1", showInCollapsedMode:=True, nodes:=New List(Of Node)() From {Node.Create("Item 1.1"), Node.Create("Item 1.2")}))
result.Add(Node.Create("Item 2", isCustomView:=True, nodes:=New List(Of Node)() From {Node.Create("Item 2.1")}))
result.Add(Node.Create("Item 3", nodes:=New List(Of Node)() From {Node.Create("Item 3.1"), Node.Create("Item 3.2", showInCollapsedMode:=True, isCustomView:=True)}))
Return result
End Function
Public Overridable Sub UpdateCustomItems()
For Each flattenItem In Flatten(Items)
flattenItem.IsCustomView = random.Next(0, 100) < 30
Next
End Sub
Private Function Flatten(ByVal e As IEnumerable(Of Node)) As IEnumerable(Of Node)
Return If(e Is Nothing, Enumerable.Empty(Of Node)(), e.SelectMany(Function(c) Flatten(c.Nodes)).Concat(e))
End Function
End Class
Public Class Node
Private _Header As String, _ShowInCollapsedMode As Boolean, _Nodes As List(Of AppearanceCustomization.Node), _Index As Integer
Public Shared Function Create(ByVal header As String, ByVal Optional showInCollapsedMode As Boolean = False, ByVal Optional isCustomView As Boolean = False, ByVal Optional nodes As List(Of Node) = Nothing) As Node
Dim factory = ViewModelSource.Factory(Of String, Boolean, Boolean, List(Of Node), Node)(Function(s, collapseMode, customView, children) New Node(s, collapseMode, customView, children))
Return factory(header, showInCollapsedMode, isCustomView, nodes)
End Function
Protected Sub New(ByVal header As String, ByVal showInCollapsedMode As Boolean, ByVal isCustomView As Boolean, ByVal nodes As List(Of Node))
Me.Header = header
Me.ShowInCollapsedMode = showInCollapsedMode
Me.IsCustomView = isCustomView
Me.Nodes = nodes
Index = counter
counter += 1
End Sub
Private Shared counter As Integer
Public Property Header As String
Get
Return _Header
End Get
Private Set(ByVal value As String)
_Header = value
End Set
End Property
Public Property ShowInCollapsedMode As Boolean
Get
Return _ShowInCollapsedMode
End Get
Private Set(ByVal value As Boolean)
_ShowInCollapsedMode = value
End Set
End Property
Public Overridable Property IsCustomView As Boolean
Public Property Nodes As List(Of Node)
Get
Return _Nodes
End Get
Private Set(ByVal value As List(Of Node))
_Nodes = value
End Set
End Property
Public Property Index As Integer
Get
Return _Index
End Get
Private Set(ByVal value As Integer)
_Index = value
End Set
End Property
End Class
End Namespace