-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainViewModel.vb
105 lines (84 loc) · 3.6 KB
/
MainViewModel.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
Imports System.Collections.Generic
Imports System.Collections.ObjectModel
Imports System.ComponentModel
Imports System.Linq
Imports System.Windows.Input
Imports DevExpress.Data
Imports DevExpress.Mvvm
Imports DevExpress.Mvvm.Native
Imports DevExpress.Mvvm.Xpf
Namespace Unbound_Columns
Public Class MainViewModel
Inherits ViewModelBase
Public Property Columns As ObservableCollection(Of Column)
Get
Return GetProperty(Function() Me.Columns)
End Get
Set(ByVal value As ObservableCollection(Of Column))
SetProperty(Function() Columns, value)
End Set
End Property
Public ReadOnly Property Items As ObservableCollection(Of Item)
Public Sub New()
Items = New ObservableCollection(Of Item)(Enumerable.Range(0, 10).[Select](Function(i) New Item With {.Id = i}))
Items.ForEach(Sub(x)
x("Name") = $"Item {Items.IndexOf(x)}"
x("CreatedAt") = Date.Now.AddDays(Items.IndexOf(x))
End Sub)
Columns = New ObservableCollection(Of Column) From {New Column() With {.FieldName = "Id"}, New Column() With {.FieldName = "Name", .UnboundType = UnboundColumnType.String}, New Column() With {.FieldName = "CreatedAt", .UnboundType = UnboundColumnType.DateTime}}
OnCustomUnboundColumnDataCommand = New DelegateCommand(Of UnboundColumnRowArgs)(AddressOf OnCustomUnboundColumnData)
AddColumnCommand = New DelegateCommand(AddressOf AddColumn)
End Sub
Public Sub OnCustomUnboundColumnData(ByVal e As UnboundColumnRowArgs)
If e.IsGetData Then e.Value = Items(e.SourceIndex)(e.FieldName)
If e.IsSetData Then Items(e.SourceIndex)(e.FieldName) = e.Value
End Sub
Public Sub AddColumn()
Columns.Add(New Column With {.FieldName = $"Value {Columns.Count}", .UnboundType = UnboundColumnType.Integer})
End Sub
Public ReadOnly Property OnCustomUnboundColumnDataCommand As ICommand
Public ReadOnly Property AddColumnCommand As ICommand
End Class
Public Class Item
Inherits BindableBase
Private ReadOnly _customFieldValues As Dictionary(Of String, Object) = New Dictionary(Of String, Object)()
Public Property Id As Integer
Get
Return GetProperty(Function() Me.Id)
End Get
Set(ByVal value As Integer)
SetProperty(Function() Id, value)
End Set
End Property
Default Public Property Item(ByVal fieldName As String) As Object
Get
Dim value As Object = Nothing
_customFieldValues.TryGetValue(fieldName, value)
Return value
End Get
Set(ByVal value As Object)
_customFieldValues(fieldName) = value
RaisePropertyChanged(fieldName)
End Set
End Property
End Class
Public Class Column
Inherits BindableBase
Public Property FieldName As String
Get
Return GetProperty(Function() Me.FieldName)
End Get
Set(ByVal value As String)
SetProperty(Function() FieldName, value)
End Set
End Property
Public Property UnboundType As UnboundColumnType?
Get
Return GetProperty(Function() Me.UnboundType)
End Get
Set(ByVal value As UnboundColumnType?)
SetProperty(Function() UnboundType, value)
End Set
End Property
End Class
End Namespace