-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainViewModel.vb
65 lines (51 loc) · 2.11 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
Imports DevExpress.Mvvm
Imports DevExpress.Mvvm.DataAnnotations
Imports DevExpress.Mvvm.Xpf
Imports System
Imports System.Collections.Generic
Imports System.Collections.ObjectModel
Imports System.Linq
Namespace CustomGrouping_MVVM
Public Class Person
Public Property FirstName As String
Public Property LastName As String
Public Property UnitPrice As Integer
Public Sub New()
End Sub
Public Sub New(ByVal i As Integer)
FirstName = "FirstName" & i
LastName = "LastName" & i
UnitPrice = i
End Sub
End Class
Public Class MainViewModel
Inherits ViewModelBase
Public ReadOnly Property ListPerson As ObservableCollection(Of Person)
Public Sub New()
ListPerson = New ObservableCollection(Of Person)(GetPersonList())
End Sub
Private Shared Function GetPersonList() As IEnumerable(Of Person)
Return Enumerable.Range(0, 100).[Select](Function(i) New Person(i))
End Function
<Command>
Public Sub CustomColumnGroup(ByVal args As RowSortArgs)
If Not Equals(args.FieldName, "UnitPrice") Then Return
Dim x As Double = Math.Floor(Convert.ToDouble(args.FirstValue) / 10)
Dim y As Double = Math.Floor(Convert.ToDouble(args.SecondValue) / 10)
args.Result = If(x > 9 AndAlso y > 9, 0, x.CompareTo(y))
End Sub
<Command>
Public Sub CustomGroupDisplayText(ByVal args As GroupDisplayTextArgs)
If Not Equals(args.FieldName, "UnitPrice") Then Return
Dim interval As String = IntervalByValue(args.Value)
args.DisplayText = interval
End Sub
' Gets the interval which contains the specified value.
Private Function IntervalByValue(ByVal val As Object) As String
Dim d As Double = Math.Floor(Convert.ToDouble(val) / 10)
Dim ret As String = String.Format("{0:c} - {1:c} ", d * 10, (d + 1) * 10)
If d > 9 Then ret = String.Format(">= {0:c} ", 100)
Return ret
End Function
End Class
End Namespace