-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMainViewModel.vb
More file actions
107 lines (86 loc) · 2.84 KB
/
MainViewModel.vb
File metadata and controls
107 lines (86 loc) · 2.84 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
104
105
106
107
Imports DevExpress.Mvvm
Imports DevExpress.Mvvm.DataAnnotations
Imports DevExpress.Mvvm.Xpf
Imports System
Imports System.Collections.ObjectModel
Imports System.ComponentModel
Imports System.Linq
Imports System.Threading
Namespace LockOnRowEdit_MVVM
Public Class DataItem
Inherits BindableBase
Public Property Id As Integer
Get
Return GetValue(Of Integer)()
End Get
Set(ByVal value As Integer)
SetValue(value)
End Set
End Property
Public Property Name As String
Get
Return GetValue(Of String)()
End Get
Set(ByVal value As String)
SetValue(value)
End Set
End Property
Public Property Value As Integer
Get
Return GetValue(Of Integer)()
End Get
Set(ByVal value As Integer)
SetValue(value)
End Set
End Property
Public Property ShouldUpdate As Boolean
Get
Return GetValue(Of Boolean)()
End Get
Set(ByVal value As Boolean)
SetValue(value)
End Set
End Property
Public Sub New(ByVal random As Random, ByVal id As Integer)
Me.Id = id
Name = $"Item {id}"
Value = random.Next(1, 100)
ShouldUpdate = True
End Sub
End Class
Public Class MainViewModel
Inherits ViewModelBase
Public Property Data As ObservableCollection(Of DataItem)
Get
Return GetValue(Of ObservableCollection(Of DataItem))()
End Get
Set(ByVal value As ObservableCollection(Of DataItem))
SetValue(value)
End Set
End Property
Private random As Random
Private updateTimer As Timer
Private updatesLocker As Boolean
Public Sub New()
random = New Random()
Data = New ObservableCollection(Of DataItem)(Enumerable.Range(0, 20).[Select](Function(i) New DataItem(random, i)))
updateTimer = New Timer(AddressOf UpdateRows, Nothing, 0, 1)
End Sub
<Command>
Public Sub LockUpdates(ByVal args As RowEditStartedArgs)
Volatile.Write(updatesLocker, True)
End Sub
<Command>
Public Sub UnlockUpdates(ByVal args As RowEditFinishedArgs)
Volatile.Write(updatesLocker, False)
End Sub
Private Sub UpdateRows(ByVal parameter As Object)
If Not Volatile.Read(updatesLocker) Then
Dim row = Data(random.Next(0, Data.Count))
If row.ShouldUpdate Then
row.Value = random.Next(1, 100)
End If
End If
End Sub
End Class
End Namespace