/
Window1.xaml.vb
81 lines (68 loc) · 2.7 KB
/
Window1.xaml.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
'#Region "#Reference"
Imports System
Imports System.ComponentModel
Imports System.Globalization
Imports System.Windows
Imports System.Windows.Data
Imports DevExpress.Xpf.Printing
' ...
'#End Region ' #Reference
Namespace UseCollectionViewLink
Public Partial Class Window1
Inherits Window
Public Sub New()
Me.InitializeComponent()
End Sub
'#Region "#CollectionViewLink"
Private Sub button1_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
' Create a link and bind it to the PrintPreview instance.
Dim link As CollectionViewLink = New CollectionViewLink()
'preview.Model = new LinkPreviewModel(link);
' Create an ICollectionView object.
link.CollectionView = CreateMonthCollectionView()
' Provide export templates.
link.DetailTemplate = CType(Resources("monthNameTemplate"), DataTemplate)
link.GroupInfos.Add(New GroupInfo(CType(Resources("monthQuarterTemplate"), DataTemplate)))
' Create a document.
link.CreateDocument(True)
' Show a Print Preview.
PrintHelper.ShowPrintPreviewDialog(Me, link)
End Sub
Private Function CreateMonthCollectionView() As ICollectionView
Const monthCount As Integer = 12
Dim monthNames As String() = CultureInfo.CurrentCulture.DateTimeFormat.MonthNames
Dim data As MonthItem() = New MonthItem(Math.Min(monthNames.Length, monthCount) - 1) {}
For i As Integer = 0 To data.Length - 1
data(i) = New MonthItem(monthNames(i), i \ 3 + 1)
Next
Dim source As CollectionViewSource = New CollectionViewSource()
source.Source = data
source.GroupDescriptions.Add(New PropertyGroupDescription("Quarter"))
Return source.View
End Function
Public Class MonthItem
Private _Name As String, _Quarter As Integer
Public Property Name As String
Get
Return _Name
End Get
Private Set(ByVal value As String)
_Name = value
End Set
End Property
Public Property Quarter As Integer
Get
Return _Quarter
End Get
Private Set(ByVal value As Integer)
_Quarter = value
End Set
End Property
Public Sub New(ByVal name As String, ByVal quarter As Integer)
Me.Name = name
Me.Quarter = quarter
End Sub
End Class
'#End Region ' #CollectionViewLink
End Class
End Namespace