Skip to content

Commit 43ac943

Browse files
committed
9433023 - Added sample for customize default zoom percentage
1 parent f595e0f commit 43ac943

16 files changed

+604
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
5+
</startup>
6+
</configuration>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Application x:Class="CustomizeDefaultZoomOnCtrlScroll.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:CustomizeDefaultZoomOnCtrlScroll"
5+
StartupUri="MainWindow.xaml">
6+
<Application.Resources>
7+
8+
</Application.Resources>
9+
</Application>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Configuration;
4+
using System.Data;
5+
using System.Linq;
6+
using System.Threading.Tasks;
7+
using System.Windows;
8+
9+
namespace CustomizeDefaultZoomOnCtrlScroll
10+
{
11+
/// <summary>
12+
/// Interaction logic for App.xaml
13+
/// </summary>
14+
public partial class App : Application
15+
{
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{F7DDED17-5585-4534-AFA3-DF9840A55B71}</ProjectGuid>
8+
<OutputType>WinExe</OutputType>
9+
<RootNamespace>CustomizeDefaultZoomOnCtrlScroll</RootNamespace>
10+
<AssemblyName>CustomizeDefaultZoomOnCtrlScroll</AssemblyName>
11+
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
14+
<WarningLevel>4</WarningLevel>
15+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
16+
<Deterministic>true</Deterministic>
17+
<TargetFrameworkProfile />
18+
</PropertyGroup>
19+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
20+
<PlatformTarget>AnyCPU</PlatformTarget>
21+
<DebugSymbols>true</DebugSymbols>
22+
<DebugType>full</DebugType>
23+
<Optimize>false</Optimize>
24+
<OutputPath>bin\Debug\</OutputPath>
25+
<DefineConstants>DEBUG;TRACE</DefineConstants>
26+
<ErrorReport>prompt</ErrorReport>
27+
<WarningLevel>4</WarningLevel>
28+
</PropertyGroup>
29+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
30+
<PlatformTarget>AnyCPU</PlatformTarget>
31+
<DebugType>pdbonly</DebugType>
32+
<Optimize>true</Optimize>
33+
<OutputPath>bin\Release\</OutputPath>
34+
<DefineConstants>TRACE</DefineConstants>
35+
<ErrorReport>prompt</ErrorReport>
36+
<WarningLevel>4</WarningLevel>
37+
</PropertyGroup>
38+
<ItemGroup>
39+
<PackageReference Include="Syncfusion.PdfViewer.WPF" Version="*" />
40+
<Reference Include="System" />
41+
<Reference Include="System.Data" />
42+
<Reference Include="System.Xml" />
43+
<Reference Include="Microsoft.CSharp" />
44+
<Reference Include="System.Core" />
45+
<Reference Include="System.Xml.Linq" />
46+
<Reference Include="System.Data.DataSetExtensions" />
47+
<Reference Include="System.Net.Http" />
48+
<Reference Include="System.Xaml">
49+
<RequiredTargetFramework>4.0</RequiredTargetFramework>
50+
</Reference>
51+
<Reference Include="WindowsBase" />
52+
<Reference Include="PresentationCore" />
53+
<Reference Include="PresentationFramework" />
54+
</ItemGroup>
55+
<ItemGroup>
56+
<ApplicationDefinition Include="App.xaml">
57+
<Generator>MSBuild:Compile</Generator>
58+
<SubType>Designer</SubType>
59+
</ApplicationDefinition>
60+
<Page Include="MainWindow.xaml">
61+
<Generator>MSBuild:Compile</Generator>
62+
<SubType>Designer</SubType>
63+
</Page>
64+
<Compile Include="App.xaml.cs">
65+
<DependentUpon>App.xaml</DependentUpon>
66+
<SubType>Code</SubType>
67+
</Compile>
68+
<Compile Include="MainWindow.xaml.cs">
69+
<DependentUpon>MainWindow.xaml</DependentUpon>
70+
<SubType>Code</SubType>
71+
</Compile>
72+
</ItemGroup>
73+
<ItemGroup>
74+
<Compile Include="Properties\AssemblyInfo.cs">
75+
<SubType>Code</SubType>
76+
</Compile>
77+
<Compile Include="Properties\Resources.Designer.cs">
78+
<AutoGen>True</AutoGen>
79+
<DesignTime>True</DesignTime>
80+
<DependentUpon>Resources.resx</DependentUpon>
81+
</Compile>
82+
<Compile Include="Properties\Settings.Designer.cs">
83+
<AutoGen>True</AutoGen>
84+
<DependentUpon>Settings.settings</DependentUpon>
85+
<DesignTimeSharedInput>True</DesignTimeSharedInput>
86+
</Compile>
87+
<EmbeddedResource Include="Properties\Resources.resx">
88+
<Generator>ResXFileCodeGenerator</Generator>
89+
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
90+
</EmbeddedResource>
91+
<None Include="packages.config" />
92+
<None Include="Properties\Settings.settings">
93+
<Generator>SettingsSingleFileGenerator</Generator>
94+
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
95+
</None>
96+
</ItemGroup>
97+
<ItemGroup>
98+
<None Include="App.config" />
99+
</ItemGroup>
100+
<ItemGroup>
101+
<PackageReference Include="Syncfusion.PdfViewer.WPF">
102+
<Version>29.2.5</Version>
103+
</PackageReference>
104+
</ItemGroup>
105+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
106+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.12.35527.113
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CustomizeDefaultZoomOnCtrlScroll", "CustomizeDefaultZoomOnCtrlScroll.csproj", "{F7DDED17-5585-4534-AFA3-DF9840A55B71}"
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+
{F7DDED17-5585-4534-AFA3-DF9840A55B71}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{F7DDED17-5585-4534-AFA3-DF9840A55B71}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{F7DDED17-5585-4534-AFA3-DF9840A55B71}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{F7DDED17-5585-4534-AFA3-DF9840A55B71}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>WinExe</OutputType>
5+
<TargetFramework>net8.0-windows</TargetFramework>
6+
<Nullable>enable</Nullable>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<UseWPF>true</UseWPF>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.PdfViewer.WPF" Version="*" />
13+
</ItemGroup>
14+
15+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.12.35707.178 d17.12
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CustomizeDefaultZoomOnCtrlScroll_NET", "CustomizeDefaultZoomOnCtrlScroll_NET.csproj", "{7AAE624F-DEC5-46C3-BA6E-38B81DE8D048}"
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+
{7AAE624F-DEC5-46C3-BA6E-38B81DE8D048}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{7AAE624F-DEC5-46C3-BA6E-38B81DE8D048}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{7AAE624F-DEC5-46C3-BA6E-38B81DE8D048}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{7AAE624F-DEC5-46C3-BA6E-38B81DE8D048}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Window xmlns:PdfViewer="clr-namespace:Syncfusion.Windows.PdfViewer;assembly=Syncfusion.PdfViewer.WPF" x:Class="CustomizeDefaultZoomOnCtrlScroll.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:CustomizeDefaultZoomOnCtrlScroll"
7+
mc:Ignorable="d"
8+
Title="MainWindow" Height="450" Width="800">
9+
<Grid>
10+
<PdfViewer:PdfViewerControl Name="PDFViewer" />
11+
</Grid>
12+
</Window>
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
using Syncfusion.Windows.PdfViewer;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Reflection;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
using System.Windows;
9+
using System.Windows.Controls;
10+
using System.Windows.Data;
11+
using System.Windows.Documents;
12+
using System.Windows.Input;
13+
using System.Windows.Media;
14+
using System.Windows.Media.Imaging;
15+
using System.Windows.Navigation;
16+
using System.Windows.Shapes;
17+
18+
namespace CustomizeDefaultZoomOnCtrlScroll
19+
{
20+
/// <summary>
21+
/// Interaction logic for MainWindow.xaml
22+
/// </summary>
23+
public partial class MainWindow : Window
24+
{
25+
string filePath;
26+
public MainWindow()
27+
{
28+
InitializeComponent();
29+
#if NETCOREAPP
30+
filePath = "../../../Data/Input.pdf";
31+
#else
32+
filePath = "../../Data/Input.pdf";
33+
#endif
34+
PDFViewer.Load(filePath);
35+
36+
PDFViewer.Loaded += PDFViewer_Loaded;
37+
38+
PDFViewer.PreviewMouseWheel += PDFViewer_PreviewMouseWheel;
39+
40+
}
41+
42+
private void PDFViewer_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
43+
{
44+
if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
45+
{
46+
if (e.Delta > 0)
47+
{
48+
int currentZoom = (PDFViewer.ZoomPercentage + 5) - 25;
49+
PDFViewer.ZoomTo(currentZoom);
50+
}
51+
else
52+
{
53+
int currentZoom = (PDFViewer.ZoomPercentage - 5) + 25;
54+
PDFViewer.ZoomTo(currentZoom);
55+
}
56+
}
57+
e.Handled = true;
58+
}
59+
60+
61+
private void PDFViewer_Loaded(object sender, RoutedEventArgs e)
62+
{
63+
// Access the toolbar from PDF Viewer template.
64+
DocumentToolbar toolbar = PDFViewer.Template.FindName("PART_Toolbar", PDFViewer) as DocumentToolbar;
65+
66+
//Get the buttons from the toolbar
67+
Button zoominbutton = (Button)toolbar.Template.FindName("PART_ButtonZoomIn", toolbar);
68+
Button zoomoutbutton = (Button)toolbar.Template.FindName("PART_ButtonZoomOut", toolbar);
69+
70+
//Remove the existing click event for button
71+
RemoveClickEvents(zoomoutbutton);
72+
RemoveClickEvents(zoominbutton);
73+
74+
//Add the new click event for the buttons
75+
zoominbutton.Click += Zoominbutton_Click;
76+
zoomoutbutton.Click += Zoomoutbutton_Click;
77+
}
78+
79+
80+
//Method used to reomve the existing click event
81+
private void RemoveClickEvents(System.Windows.Controls.Button b)
82+
{
83+
RoutedEventHandlerInfo[] routedEventHandlers = GetRoutedEventHandlerss(b, System.Windows.Controls.Button.ClickEvent);
84+
foreach (RoutedEventHandlerInfo routedEventHandler in routedEventHandlers)
85+
b.Click -= (RoutedEventHandler)routedEventHandler.Handler;
86+
}
87+
88+
public static RoutedEventHandlerInfo[] GetRoutedEventHandlerss(UIElement element, RoutedEvent routedEvent)
89+
{
90+
PropertyInfo eventHandlersStoreProperty = typeof(UIElement).GetProperty("EventHandlersStore", BindingFlags.Instance | BindingFlags.NonPublic);
91+
object eventHandlersStore = eventHandlersStoreProperty.GetValue(element, null/* TODO Change to default(_) if this is not a reference type */);
92+
93+
MethodInfo getRoutedEventHandler = eventHandlersStore.GetType().GetMethod("GetRoutedEventHandlers", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
94+
RoutedEventHandlerInfo[] routedEventHandlers = (RoutedEventHandlerInfo[])getRoutedEventHandler.Invoke(eventHandlersStore, new object[] { routedEvent });
95+
96+
return routedEventHandlers;
97+
}
98+
99+
100+
private void Zoomoutbutton_Click(object sender, RoutedEventArgs e)
101+
{
102+
//set the zoom out percentage
103+
int currentZoom = PDFViewer.ZoomPercentage - 5;
104+
PDFViewer.ZoomTo(currentZoom);
105+
}
106+
107+
private void Zoominbutton_Click(object sender, RoutedEventArgs e)
108+
{
109+
// set the zoom in percentage
110+
int currentZoom = PDFViewer.ZoomPercentage + 5;
111+
PDFViewer.ZoomTo(currentZoom);
112+
}
113+
}
114+
}
115+
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System.Reflection;
2+
using System.Resources;
3+
using System.Runtime.CompilerServices;
4+
using System.Runtime.InteropServices;
5+
using System.Windows;
6+
7+
// General Information about an assembly is controlled through the following
8+
// set of attributes. Change these attribute values to modify the information
9+
// associated with an assembly.
10+
[assembly: AssemblyDescription("")]
11+
[assembly: AssemblyCopyright("Copyright © 2025")]
12+
[assembly: AssemblyTrademark("")]
13+
[assembly: AssemblyCulture("")]
14+
15+
// Setting ComVisible to false makes the types in this assembly not visible
16+
// to COM components. If you need to access a type in this assembly from
17+
// COM, set the ComVisible attribute to true on that type.
18+
[assembly: ComVisible(false)]
19+
20+
//In order to begin building localizable applications, set
21+
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
22+
//inside a <PropertyGroup>. For example, if you are using US english
23+
//in your source files, set the <UICulture> to en-US. Then uncomment
24+
//the NeutralResourceLanguage attribute below. Update the "en-US" in
25+
//the line below to match the UICulture setting in the project file.
26+
27+
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
28+
29+
30+
[assembly: ThemeInfo(
31+
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
32+
//(used if a resource is not found in the page,
33+
// or application resource dictionaries)
34+
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
35+
//(used if a resource is not found in the page,
36+
// app, or any theme specific resource dictionaries)
37+
)]
38+
39+
40+
// Version information for an assembly consists of the following four values:
41+
//
42+
// Major Version
43+
// Minor Version
44+
// Build Number
45+
// Revision
46+
//

0 commit comments

Comments
 (0)