Skip to content

Commit fad3bf2

Browse files
authored
Merge pull request #74 from SyncfusionExamples/900666_Customcontextmenusample
900666 : Update sample for How to add custom context menu to the WPF PdfViewer
2 parents 58c2f90 + 7b923d4 commit fad3bf2

File tree

9 files changed

+160
-0
lines changed

9 files changed

+160
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Application x:Class="CustomContextMenu.App"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:local="clr-namespace:CustomContextMenu"
5+
StartupUri="MainWindow.xaml">
6+
<Application.Resources>
7+
8+
</Application.Resources>
9+
</Application>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System.Configuration;
2+
using System.Data;
3+
using System.Windows;
4+
5+
namespace CustomContextMenu
6+
{
7+
/// <summary>
8+
/// Interaction logic for App.xaml
9+
/// </summary>
10+
public partial class App : Application
11+
{
12+
}
13+
14+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System.Windows;
2+
3+
[assembly: ThemeInfo(
4+
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
5+
//(used if a resource is not found in the page,
6+
// or application resource dictionaries)
7+
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
8+
//(used if a resource is not found in the page,
9+
// app, or any theme specific resource dictionaries)
10+
)]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>WinExe</OutputType>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="Syncfusion.PdfViewer.WPF" Version="*" />
9+
<PackageReference Include="System.Drawing.Common" Version="9.0.8" />
10+
</ItemGroup>
11+
<Import Project="targets\MultiTargeting.targets" />
12+
</Project>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.14.36401.2
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CustomContextMenu", "CustomContextMenu.csproj", "{0FAA7523-B034-4EA9-860A-A8936DFFD40E}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{0FAA7523-B034-4EA9-860A-A8936DFFD40E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{0FAA7523-B034-4EA9-860A-A8936DFFD40E}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{0FAA7523-B034-4EA9-860A-A8936DFFD40E}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{0FAA7523-B034-4EA9-860A-A8936DFFD40E}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {BAAD6341-6945-42C7-8438-919E9DB8EB03}
24+
EndGlobalSection
25+
EndGlobal
205 KB
Binary file not shown.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Window x:Class="CustomContextMenu.MainWindow"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
xmlns:local="clr-namespace:CustomContextMenu" xmlns:PdfViewer="clr-namespace:Syncfusion.Windows.PdfViewer;assembly=Syncfusion.PdfViewer.WPF"
7+
mc:Ignorable="d"
8+
Title="MainWindow"
9+
WindowState="Maximized">
10+
<Grid>
11+
<PdfViewer:PdfViewerControl x:Name="pdfViewer" />
12+
</Grid>
13+
</Window>
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project>
2+
<PropertyGroup>
3+
<TargetFrameworks>net462;net8.0-windows;net9.0-windows</TargetFrameworks>
4+
<UseWPF>true</UseWPF>
5+
<GenerateAssemblyInfo>False</GenerateAssemblyInfo>
6+
<GenerateDocumentationFile>True</GenerateDocumentationFile>
7+
<EnableDefaultItems>True</EnableDefaultItems>
8+
<EnableDefaultEmbeddedResourceItems>True</EnableDefaultEmbeddedResourceItems>
9+
</PropertyGroup>
10+
</Project>

0 commit comments

Comments
 (0)