Skip to content

Commit 7b923d4

Browse files
900666_Customcontextmenusample
1 parent a9e18d8 commit 7b923d4

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

ContextMenu/CustomContextMenu/MainWindow.xaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
66
xmlns:local="clr-namespace:CustomContextMenu" xmlns:PdfViewer="clr-namespace:Syncfusion.Windows.PdfViewer;assembly=Syncfusion.PdfViewer.WPF"
77
mc:Ignorable="d"
8-
Title="MainWindow" Height="450" Width="800">
8+
Title="MainWindow"
9+
WindowState="Maximized">
910
<Grid>
1011
<PdfViewer:PdfViewerControl x:Name="pdfViewer" />
1112
</Grid>

ContextMenu/CustomContextMenu/MainWindow.xaml.cs

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,27 @@ private void FitToPageMenuItem_Click(object sender, RoutedEventArgs e)
4141
}
4242
private void PdfViewer_ContextMenuOpening(object sender, ContextMenuOpeningEventArgs e)
4343
{
44-
ContextMenu contextmenu = new ContextMenu();
45-
contextmenu.FlowDirection = FlowDirection.LeftToRight;
46-
contextmenu.HorizontalAlignment = HorizontalAlignment.Center;
47-
MenuItem selectZoomArea = new MenuItem();
48-
selectZoomArea.Header = "Select Zoom Area";
49-
selectZoomArea.Click += SelectZoomArea_Click;
50-
contextmenu.Items.Add(selectZoomArea);
51-
MenuItem fitToPageMenuItem = new MenuItem();
52-
fitToPageMenuItem.Header = "Fit to Page";
53-
fitToPageMenuItem.Click += FitToPageMenuItem_Click;
54-
contextmenu.Items.Add(fitToPageMenuItem);
55-
MenuItem pan = new MenuItem();
56-
pan.Header = "Pan";
57-
pan.Click += Pan_Click;
58-
contextmenu.Items.Add(pan);
59-
contextmenu.IsOpen = true;
60-
contextmenu.StaysOpen = true;
61-
e.Handled = true;
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+
}
6265
}
6366
}
6467
}

0 commit comments

Comments
 (0)