1+ using Syncfusion . Windows . PdfViewer ;
2+ using System ;
3+ using System . Text ;
4+ using System . Windows ;
5+ using System . Windows . Controls ;
6+ using System . Windows . Data ;
7+ using System . Windows . Documents ;
8+ using System . Windows . Input ;
9+ using System . Windows . Media ;
10+ using System . Windows . Media . Imaging ;
11+ using System . Windows . Navigation ;
12+ using System . Windows . Shapes ;
13+
14+ namespace CustomContextMenu
15+ {
16+ /// <summary>
17+ /// Interaction logic for MainWindow.xaml
18+ /// </summary>
19+ public partial class MainWindow : Window
20+ {
21+ public MainWindow ( )
22+ {
23+ InitializeComponent ( ) ;
24+ pdfViewer . Load ( "../../../Data/Input.pdf" ) ;
25+ pdfViewer . ContextMenuOpening += PdfViewer_ContextMenuOpening ;
26+ }
27+
28+ private void Pan_Click ( object sender , RoutedEventArgs e )
29+ {
30+ pdfViewer . CursorMode = PdfViewerCursorMode . HandTool ;
31+ }
32+
33+ private void SelectZoomArea_Click ( object sender , RoutedEventArgs e )
34+ {
35+ pdfViewer . CursorMode = PdfViewerCursorMode . MarqueeZoom ;
36+ }
37+
38+ private void FitToPageMenuItem_Click ( object sender , RoutedEventArgs e )
39+ {
40+ pdfViewer . ZoomMode = Syncfusion . Windows . PdfViewer . ZoomMode . FitPage ;
41+ }
42+ private void PdfViewer_ContextMenuOpening ( object sender , ContextMenuOpeningEventArgs e )
43+ {
44+ if ( e . Source == "Text Selection" )
45+ {
46+ ContextMenu contextmenu = new ContextMenu ( ) ;
47+ contextmenu . FlowDirection = FlowDirection . LeftToRight ;
48+ contextmenu . HorizontalAlignment = HorizontalAlignment . Center ;
49+ MenuItem selectZoomArea = new MenuItem ( ) ;
50+ selectZoomArea . Header = "Select Zoom Area" ;
51+ selectZoomArea . Click += SelectZoomArea_Click ;
52+ contextmenu . Items . Add ( selectZoomArea ) ;
53+ MenuItem fitToPageMenuItem = new MenuItem ( ) ;
54+ fitToPageMenuItem . Header = "Fit to Page" ;
55+ fitToPageMenuItem . Click += FitToPageMenuItem_Click ;
56+ contextmenu . Items . Add ( fitToPageMenuItem ) ;
57+ MenuItem pan = new MenuItem ( ) ;
58+ pan . Header = "Pan" ;
59+ pan . Click += Pan_Click ;
60+ contextmenu . Items . Add ( pan ) ;
61+ contextmenu . IsOpen = true ;
62+ contextmenu . StaysOpen = true ;
63+ e . Handled = true ;
64+ }
65+ }
66+ }
67+ }
0 commit comments