-
Notifications
You must be signed in to change notification settings - Fork 2
/
ViewModel.vb
358 lines (342 loc) · 8.95 KB
/
ViewModel.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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
Imports System
Imports System.Collections
Imports System.Collections.Generic
Imports System.Collections.ObjectModel
Imports System.Linq
Imports System.Reflection
Imports System.Xml.Serialization
Imports DevExpress.Data
Imports DevExpress.Mvvm
Namespace Model
Public Class ViewModel
Inherits ViewModelBase
Public Property States() As ObservableCollection(Of String)
Get
Return GetProperty(Function() States)
End Get
Private Set(ByVal value As ObservableCollection(Of String))
SetProperty(Function() States, value)
End Set
End Property
Public Property Source() As IList(Of Employee)
Get
Return GetProperty(Function() Source)
End Get
Private Set(ByVal value As IList(Of Employee))
SetProperty(Function() Source, value)
End Set
End Property
Public Property Columns() As ObservableCollection(Of Column)
Get
Return GetProperty(Function() Columns)
End Get
Private Set(ByVal value As ObservableCollection(Of Column))
SetProperty(Function() Columns, value)
End Set
End Property
Public Property TotalSummary() As ObservableCollection(Of Summary)
Get
Return GetProperty(Function() TotalSummary)
End Get
Private Set(ByVal value As ObservableCollection(Of Summary))
SetProperty(Function() TotalSummary, value)
End Set
End Property
Public Property GroupSummary() As ObservableCollection(Of Summary)
Get
Return GetProperty(Function() GroupSummary)
End Get
Private Set(ByVal value As ObservableCollection(Of Summary))
SetProperty(Function() GroupSummary, value)
End Set
End Property
Public Sub New()
Source = EmployeesData.DataSource
States = New ObservableCollection(Of String)(Source.Select(Function(x) x.StateProvinceName).Distinct())
Columns = New ObservableCollection(Of Column)() From {
New Column() With {.FieldName="FirstName"},
New Column() With {.FieldName="LastName"},
New Column() With {
.FieldName="BirthDate",
.Settings = SettingsType.Date
},
New ComboColumn() With {
.Settings = SettingsType.Combo,
.FieldName="StateProvinceName",
.Source = States
},
New HeaderColumn() With {
.Settings = SettingsType.Binding,
.FieldName = "Cities[0]",
.Header = "City1"
},
New HeaderColumn() With {
.Settings = SettingsType.Binding,
.FieldName = "Cities[1]",
.Header = "City2"
},
New Column() With {
.FieldName="ImageData",
.Settings = SettingsType.Image
}
}
TotalSummary = New ObservableCollection(Of Summary)() From {
New Summary() With {
.Type = SummaryItemType.Count,
.FieldName = "FirstName"
},
New Summary() With {
.Type = SummaryItemType.Max,
.FieldName = "BirthDate"
}
}
GroupSummary = New ObservableCollection(Of Summary)() From {
New Summary() With {
.Type = SummaryItemType.Count,
.FieldName = "FirstName"
}
}
End Sub
End Class
Public Enum SettingsType
[Default]
Combo
Image
Binding
[Date]
End Enum
Public Class Summary
Inherits BindableBase
Public Property Type() As SummaryItemType
Get
Return GetProperty(Function() Type)
End Get
Set(ByVal value As SummaryItemType)
SetProperty(Function() Type, value)
End Set
End Property
Public Property FieldName() As String
Get
Return GetProperty(Function() FieldName)
End Get
Set(ByVal value As String)
SetProperty(Function() FieldName, value)
End Set
End Property
End Class
Public Class Column
Inherits BindableBase
Public Property FieldName() As String
Get
Return GetProperty(Function() FieldName)
End Get
Set(ByVal value As String)
SetProperty(Function() FieldName, value)
End Set
End Property
Public Property Settings() As SettingsType
Get
Return GetProperty(Function() Settings)
End Get
Set(ByVal value As SettingsType)
SetProperty(Function() Settings, value)
End Set
End Property
End Class
Public Class ComboColumn
Inherits Column
Public Property Source() As IList
Get
Return GetProperty(Function() Source)
End Get
Set(ByVal value As IList)
SetProperty(Function() Source, value)
End Set
End Property
End Class
Public Class HeaderColumn
Inherits Column
Public Property Header() As String
Get
Return GetProperty(Function() Header)
End Get
Set(ByVal value As String)
SetProperty(Function() Header, value)
End Set
End Property
End Class
<XmlRoot("Employees")>
Public Class EmployeesData
Inherits List(Of Employee)
Public Shared ReadOnly Property DataSource() As IList(Of Employee)
Get
Dim s As New XmlSerializer(GetType(EmployeesData))
Dim list = DirectCast(s.Deserialize(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("WPFGridMVVMBindableColumns.EmployeesWithPhoto.xml")), List(Of Employee))
Return New ObservableCollection(Of Employee)(list)
End Get
End Property
End Class
Public Class Employee
Inherits BindableBase
Public Property Id() As Integer
Get
Return GetProperty(Function() Id)
End Get
Set(ByVal value As Integer)
SetProperty(Function() Id, value)
End Set
End Property
Public Property ParentId() As Integer
Get
Return GetProperty(Function() ParentId)
End Get
Set(ByVal value As Integer)
SetProperty(Function() ParentId, value)
End Set
End Property
Public Property FirstName() As String
Get
Return GetProperty(Function() FirstName)
End Get
Set(ByVal value As String)
SetProperty(Function() FirstName, value)
End Set
End Property
Public Property MiddleName() As String
Get
Return GetProperty(Function() MiddleName)
End Get
Set(ByVal value As String)
SetProperty(Function() MiddleName, value)
End Set
End Property
Public Property LastName() As String
Get
Return GetProperty(Function() LastName)
End Get
Set(ByVal value As String)
SetProperty(Function() LastName, value)
End Set
End Property
Public Property JobTitle() As String
Get
Return GetProperty(Function() JobTitle)
End Get
Set(ByVal value As String)
SetProperty(Function() JobTitle, value)
End Set
End Property
Public Property Phone() As String
Get
Return GetProperty(Function() Phone)
End Get
Set(ByVal value As String)
SetProperty(Function() Phone, value)
End Set
End Property
Public Property EmailAddress() As String
Get
Return GetProperty(Function() EmailAddress)
End Get
Set(ByVal value As String)
SetProperty(Function() EmailAddress, value)
End Set
End Property
Public Property AddressLine1() As String
Get
Return GetProperty(Function() AddressLine1)
End Get
Set(ByVal value As String)
SetProperty(Function() AddressLine1, value)
End Set
End Property
Public Property Cities() As List(Of String)
Get
Return GetProperty(Function() Cities)
End Get
Set(ByVal value As List(Of String))
SetProperty(Function() Cities, value)
End Set
End Property
Public Property StateProvinceName() As String
Get
Return GetProperty(Function() StateProvinceName)
End Get
Set(ByVal value As String)
SetProperty(Function() StateProvinceName, value)
End Set
End Property
Public Property PostalCode() As String
Get
Return GetProperty(Function() PostalCode)
End Get
Set(ByVal value As String)
SetProperty(Function() PostalCode, value)
End Set
End Property
Public Property CountryRegionName() As String
Get
Return GetProperty(Function() CountryRegionName)
End Get
Set(ByVal value As String)
SetProperty(Function() CountryRegionName, value)
End Set
End Property
Public Property GroupName() As String
Get
Return GetProperty(Function() GroupName)
End Get
Set(ByVal value As String)
SetProperty(Function() GroupName, value)
End Set
End Property
Public Property BirthDate() As DateTime
Get
Return GetProperty(Function() BirthDate)
End Get
Set(ByVal value As DateTime)
SetProperty(Function() BirthDate, value)
End Set
End Property
Public Property HireDate() As DateTime
Get
Return GetProperty(Function() HireDate)
End Get
Set(ByVal value As DateTime)
SetProperty(Function() HireDate, value)
End Set
End Property
Public Property Gender() As String
Get
Return GetProperty(Function() Gender)
End Get
Set(ByVal value As String)
SetProperty(Function() Gender, value)
End Set
End Property
Public Property MaritalStatus() As String
Get
Return GetProperty(Function() MaritalStatus)
End Get
Set(ByVal value As String)
SetProperty(Function() MaritalStatus, value)
End Set
End Property
Public Property Title() As String
Get
Return GetProperty(Function() Title)
End Get
Set(ByVal value As String)
SetProperty(Function() Title, value)
End Set
End Property
Public Property ImageData() As Byte()
Get
Return GetProperty(Function() ImageData)
End Get
Set(ByVal value As Byte())
SetProperty(Function() ImageData, value)
End Set
End Property
End Class
End Namespace