-
Notifications
You must be signed in to change notification settings - Fork 1
/
ViewModel.vb
52 lines (42 loc) · 1.46 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
Imports DevExpress.Mvvm
Imports DevExpress.Mvvm.DataAnnotations
Imports System.Collections.ObjectModel
Imports System.Linq
Namespace Bars_in_MVVM_Application
Public Class ViewModel
Inherits ViewModelBase
Public Sub New()
Issues = IssueDataModel.GetIssues()
SelectedIssue = Issues.FirstOrDefault()
End Sub
Public Property Issues As ObservableCollection(Of Issue)
Get
Return GetValue(Of ObservableCollection(Of Issue))()
End Get
Set(ByVal value As ObservableCollection(Of Issue))
SetValue(value)
End Set
End Property
Public Property SelectedIssue As Issue
Get
Return GetValue(Of Issue)()
End Get
Set(ByVal value As Issue)
SetValue(value)
End Set
End Property
<Command>
Public Sub AddIssue()
Dim newId As Integer = If(Issues.Count = 0, 0, Issues.Max(Function(p) p.Id) + 1)
Dim issue As Issue = New Issue() With {.Id = newId, .Subject = "New Issue " & newId, .Completed = False, .Priority = Priority.Low}
Issues.Add(issue)
End Sub
<Command>
Public Sub RemoveIssue()
Issues.Remove(SelectedIssue)
End Sub
Public Function CanRemoveIssue() As Boolean
Return SelectedIssue IsNot Nothing
End Function
End Class
End Namespace