-
Notifications
You must be signed in to change notification settings - Fork 3
/
MainWindow.xaml.cs
153 lines (125 loc) · 5.68 KB
/
MainWindow.xaml.cs
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
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows;
using System.Windows.Input;
using DevExpress.Mvvm;
using DevExpress.Xpf.DocumentViewer;
using DevExpress.Xpf.PdfViewer;
namespace DXSample {
public partial class MainWindow : Window {
public MainWindow() {
InitializeComponent();
}
}
public class CustomPdfCommandProvider : PdfCommandProvider {
readonly List<double> factors = new List<double> { 0.15, 0.3, 0.45, 1, 1.25, 1.5, 2, 5 };
public PdfViewerControl Control { get { return DocumentViewer as PdfViewerControl; } }
ICommand zoomInCommandInternal;
protected override ICommand ZoomInCommandInternal {
get { return zoomInCommandInternal ?? (zoomInCommandInternal = new DelegateCommand(ZoomIn, CanZoomIn)); }
}
ICommand zoomOutCommandInternal;
protected override ICommand ZoomOutCommandInternal {
get { return zoomOutCommandInternal ?? (zoomOutCommandInternal = new DelegateCommand(ZoomOut, CanZoomOut)); }
}
void ZoomIn() {
if (Control == null) return;
foreach (var zoomFactor in factors) {
if (Control.ZoomFactor < zoomFactor) {
Control.ZoomFactor = zoomFactor;
break;
}
}
}
bool CanZoomIn() {
return Control != null && Control.Document != null && Control.ZoomFactor < factors[factors.Count - 1];
}
void ZoomOut() {
if (Control == null) return;
for (int i = factors.Count - 1; i >= 0; i--) {
if (factors[i] < Control.ZoomFactor) {
Control.ZoomFactor = factors[i];
break;
}
}
}
bool CanZoomOut() {
return Control != null && Control.Document != null && Control.ZoomFactor > factors[0];
}
protected override ICommand CreateZoomModeAndZoomFactorItem(string dllName) {
var items = CreateZoomModeAndFactorsItems();
CommandCheckItems setZoomModeAndFactor = new CommandCheckItems {
Caption = DocumentViewerLocalizer.GetString(DocumentViewerStringId.CommandZoomCaption),
Hint = DocumentViewerLocalizer.GetString(DocumentViewerStringId.CommandZoomDescription),
Group = DocumentViewerLocalizer.GetString(DocumentViewerStringId.ZoomRibbonGroupCaption),
Command = new DelegateCommand(() => { }, () => items.Any(x => x.CanExecute(null))),
Items = items,
SmallGlyph = UriHelper.GetUri(dllName, @"\Images\Zoom_16x16.png"),
LargeGlyph = UriHelper.GetUri(dllName, @"\Images\Zoom_32x32.png"),
};
return setZoomModeAndFactor;
}
ObservableCollection<CommandToggleButton> CreateZoomModeAndFactorsItems() {
ObservableCollection<CommandToggleButton> zoomModeAndFactorsItems = new ObservableCollection<CommandToggleButton>();
DelegateCommand<double> setZoomFactorCommand = new DelegateCommand<double>(x => {
SetZoomFactorCommandInternal.Execute(x);
UpdateZoomCommand();
}, x => SetZoomFactorCommandInternal.CanExecute(x));
zoomModeAndFactorsItems.Add(new CommandSetZoomFactorAndModeItem {
Caption = "15%",
Command = new CommandWrapper(() => setZoomFactorCommand),
ZoomFactor = 0.15,
GroupIndex = 1
});
zoomModeAndFactorsItems.Add(new CommandSetZoomFactorAndModeItem {
Caption = "30%",
Command = new CommandWrapper(() => (setZoomFactorCommand)),
ZoomFactor = 0.3,
GroupIndex = 1
});
zoomModeAndFactorsItems.Add(new CommandSetZoomFactorAndModeItem {
Caption = "45%",
Command = new CommandWrapper(() => setZoomFactorCommand),
ZoomFactor = 0.45,
GroupIndex = 1
});
zoomModeAndFactorsItems.Add(new CommandSetZoomFactorAndModeItem {
Caption = "100%",
Command = new CommandWrapper(() => setZoomFactorCommand),
ZoomFactor = 1,
GroupIndex = 1
});
zoomModeAndFactorsItems.Add(new CommandSetZoomFactorAndModeItem {
Caption = "125%",
Command = new CommandWrapper(() => setZoomFactorCommand),
ZoomFactor = 1.25,
GroupIndex = 1
});
zoomModeAndFactorsItems.Add(new CommandSetZoomFactorAndModeItem {
Caption = "150%",
Command = new CommandWrapper(() => setZoomFactorCommand),
ZoomFactor = 1.5,
GroupIndex = 1
});
zoomModeAndFactorsItems.Add(new CommandSetZoomFactorAndModeItem {
Caption = "200%",
Command = new CommandWrapper(() => setZoomFactorCommand),
ZoomFactor = 2,
GroupIndex = 1
});
zoomModeAndFactorsItems.Add(new CommandSetZoomFactorAndModeItem {
Caption = "500%",
Command = new CommandWrapper(() => setZoomFactorCommand),
ZoomFactor = 5,
GroupIndex = 1
});
return zoomModeAndFactorsItems;
}
void UpdateZoomCommand() {
CommandCheckItems zoomCommand = ZoomCommand as CommandCheckItems;
if (zoomCommand == null) return;
zoomCommand.UpdateCheckState(UpdateZoomFactorCheckState);
}
}
}