-
Notifications
You must be signed in to change notification settings - Fork 3
/
MainWindow.xaml.vb
183 lines (146 loc) · 7.01 KB
/
MainWindow.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
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
Imports System.Collections.ObjectModel
Imports DevExpress.Mvvm
Imports DevExpress.Xpf.DocumentViewer
Imports DevExpress.Xpf.PdfViewer
Namespace DXSample
Partial Public Class MainWindow
Inherits Window
Public Sub New()
InitializeComponent()
End Sub
End Class
Public Class CustomPdfCommandProvider
Inherits PdfCommandProvider
Private ReadOnly factors As New List(Of Double) From {0.15, 0.3, 0.45, 1, 1.25, 1.5, 2, 5}
Public ReadOnly Property Control() As PdfViewerControl
Get
Return TryCast(DocumentViewer, PdfViewerControl)
End Get
End Property
Private zoomInCommandInternal_Renamed As ICommand
Protected Overrides ReadOnly Property ZoomInCommandInternal() As ICommand
Get
If zoomInCommandInternal_Renamed IsNot Nothing Then
Return zoomInCommandInternal_Renamed
Else
zoomInCommandInternal_Renamed = New DelegateCommand(AddressOf ZoomIn, AddressOf CanZoomIn)
Return zoomInCommandInternal_Renamed
End If
End Get
End Property
Private zoomOutCommandInternal_Renamed As ICommand
Protected Overrides ReadOnly Property ZoomOutCommandInternal() As ICommand
Get
If zoomOutCommandInternal_Renamed IsNot Nothing Then
Return zoomOutCommandInternal_Renamed
Else
zoomOutCommandInternal_Renamed = New DelegateCommand(AddressOf ZoomOut, AddressOf CanZoomOut)
Return zoomOutCommandInternal_Renamed
End If
End Get
End Property
Private Sub ZoomIn()
If Control Is Nothing Then
Return
End If
For Each zoomFactor In factors
If Control.ZoomFactor < zoomFactor Then
Control.ZoomFactor = zoomFactor
Exit For
End If
Next zoomFactor
End Sub
Private Function CanZoomIn() As Boolean
Return Control IsNot Nothing AndAlso Control.Document IsNot Nothing AndAlso Control.ZoomFactor < factors(factors.Count - 1)
End Function
Private Sub ZoomOut()
If Control Is Nothing Then
Return
End If
For i As Integer = factors.Count - 1 To 0 Step -1
If factors(i) < Control.ZoomFactor Then
Control.ZoomFactor = factors(i)
Exit For
End If
Next i
End Sub
Private Function CanZoomOut() As Boolean
Return Control IsNot Nothing AndAlso Control.Document IsNot Nothing AndAlso Control.ZoomFactor > factors(0)
End Function
Protected Overrides Function CreateZoomModeAndZoomFactorItem(ByVal dllName As String) As ICommand
Dim items = CreateZoomModeAndFactorsItems()
Dim setZoomModeAndFactor As CommandCheckItems = New CommandCheckItems With {.Caption = DocumentViewerLocalizer.GetString(DocumentViewerStringId.CommandZoomCaption),
.Hint = DocumentViewerLocalizer.GetString(DocumentViewerStringId.CommandZoomDescription),
.Group = DocumentViewerLocalizer.GetString(DocumentViewerStringId.ZoomRibbonGroupCaption),
.Command = New DelegateCommand(Function()
End Function, Function() items.Any(Function(x) x.CanExecute(Nothing))), .Items = items,
.SmallGlyph = UriHelper.GetUri(dllName, "\Images\Zoom_16x16.png"), .LargeGlyph = UriHelper.GetUri(dllName, "\Images\Zoom_32x32.png")}
Return setZoomModeAndFactor
End Function
Private Function CreateZoomModeAndFactorsItems() As ObservableCollection(Of CommandToggleButton)
Dim zoomModeAndFactorsItems As New ObservableCollection(Of CommandToggleButton)()
Dim setZoomFactorCommand As DelegateCommand(Of Double) = New DelegateCommand(Of Double)(Function(x)
SetZoomFactorCommandInternal.Execute(x)
UpdateZoomCommand()
End Function, Function(x) SetZoomFactorCommandInternal.CanExecute(x))
zoomModeAndFactorsItems.Add(New CommandSetZoomFactorAndModeItem With {
.Caption = "15%",
.Command = New CommandWrapper(Function() setZoomFactorCommand),
.ZoomFactor = 0.15,
.GroupIndex = 1
})
zoomModeAndFactorsItems.Add(New CommandSetZoomFactorAndModeItem With {
.Caption = "30%",
.Command = New CommandWrapper(Function() (setZoomFactorCommand)),
.ZoomFactor = 0.3,
.GroupIndex = 1
})
zoomModeAndFactorsItems.Add(New CommandSetZoomFactorAndModeItem With {
.Caption = "45%",
.Command = New CommandWrapper(Function() setZoomFactorCommand),
.ZoomFactor = 0.45,
.GroupIndex = 1
})
zoomModeAndFactorsItems.Add(New CommandSetZoomFactorAndModeItem With {
.Caption = "100%",
.Command = New CommandWrapper(Function() setZoomFactorCommand),
.ZoomFactor = 1,
.GroupIndex = 1
})
zoomModeAndFactorsItems.Add(New CommandSetZoomFactorAndModeItem With {
.Caption = "125%",
.Command = New CommandWrapper(Function() setZoomFactorCommand),
.ZoomFactor = 1.25,
.GroupIndex = 1
})
zoomModeAndFactorsItems.Add(New CommandSetZoomFactorAndModeItem With {
.Caption = "150%",
.Command = New CommandWrapper(Function() setZoomFactorCommand),
.ZoomFactor = 1.5,
.GroupIndex = 1
})
zoomModeAndFactorsItems.Add(New CommandSetZoomFactorAndModeItem With {
.Caption = "200%",
.Command = New CommandWrapper(Function() setZoomFactorCommand),
.ZoomFactor = 2,
.GroupIndex = 1
})
zoomModeAndFactorsItems.Add(New CommandSetZoomFactorAndModeItem With {
.Caption = "500%",
.Command = New CommandWrapper(Function() setZoomFactorCommand),
.ZoomFactor = 5,
.GroupIndex = 1
})
Return zoomModeAndFactorsItems
End Function
Protected Overrides Function UpdateZoomFactorCheckState(item As CommandToggleButton) As Boolean
Return MyBase.UpdateZoomFactorCheckState(item)
End Function
Private Sub UpdateZoomCommand()
Dim zoomCommand As CommandCheckItems = TryCast(zoomCommand, CommandCheckItems)
If zoomCommand Is Nothing Then
End If
Return
End Sub
End Class
End Namespace