Skip to content

Commit 0230154

Browse files
authored
Merge pull request #63 from SyncfusionExamples/WPF-899377
899377 - How to hide the print file menu items and show it in main toolbar as a button
2 parents b2a6f68 + 6f1614e commit 0230154

15 files changed

+538
-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="PrintAndSaveButtonInMainToolbar.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:PrintAndSaveButtonInMainToolbar"
5+
StartupUri="MainWindow.xaml">
6+
<Application.Resources>
7+
8+
</Application.Resources>
9+
</Application>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System.Windows;
2+
3+
namespace PrintAndSaveButtonInMainToolbar
4+
{
5+
/// <summary>
6+
/// Interaction logic for App.xaml
7+
/// </summary>
8+
public partial class App : Application
9+
{
10+
}
11+
}
Binary file not shown.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<Window x:Class="PrintAndSaveButtonInMainToolbar.MainWindow"
2+
xmlns:PdfViewer="clr-namespace:Syncfusion.Windows.PdfViewer;assembly=Syncfusion.PdfViewer.WPF"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
7+
xmlns:local="clr-namespace:PrintAndSaveButtonInMainToolbar"
8+
mc:Ignorable="d"
9+
Title="MainWindow" WindowState="Maximized" Loaded="Window_Loaded">
10+
<Window.Resources>
11+
<Style x:Key="MenuIconStyle"
12+
TargetType="Path">
13+
<Style.Triggers>
14+
<Trigger Property="IsEnabled"
15+
Value="True">
16+
<Setter Property="Fill"
17+
Value="#FF485F77" />
18+
</Trigger>
19+
<Trigger Property="IsEnabled"
20+
Value="False">
21+
<Setter Property="Fill"
22+
Value="#55475F77" />
23+
</Trigger>
24+
</Style.Triggers>
25+
</Style>
26+
<Style x:Key="newButtonStyle" TargetType="{x:Type Button}">
27+
<Setter Property="Background" Value="Transparent"/>
28+
<Setter Property="Template">
29+
<Setter.Value>
30+
<ControlTemplate TargetType="{x:Type Button}">
31+
<Border Background="{TemplateBinding Background}" BorderBrush="Transparent" BorderThickness="1">
32+
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
33+
</Border>
34+
</ControlTemplate>
35+
</Setter.Value>
36+
</Setter>
37+
<Style.Triggers>
38+
<Trigger Property="IsMouseOver" Value="True">
39+
<Setter Property="Background" Value="#D5DBDF" />
40+
</Trigger>
41+
<Trigger Property="IsEnabled" Value="True">
42+
<Setter Property="Foreground" Value="#FF475F77" />
43+
</Trigger>
44+
<Trigger Property="IsEnabled" Value="False">
45+
<Setter Property="Foreground" Value="#55475F77" />
46+
<Setter Property="Background" Value="Transparent" />
47+
</Trigger>
48+
<Trigger Property="IsFocused" Value="true">
49+
<Setter Property="Foreground" Value="#FF475F77" />
50+
<Setter Property="Background" Value="#D5DBDF" />
51+
</Trigger>
52+
</Style.Triggers>
53+
</Style>
54+
</Window.Resources>
55+
<Grid>
56+
<PdfViewer:PdfViewerControl x:Name="pdfViewer"/>
57+
</Grid>
58+
</Window>
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
using Syncfusion.Windows.PdfViewer;
2+
using System;
3+
using System.Windows;
4+
using System.Windows.Controls;
5+
using System.Windows.Controls.Primitives;
6+
using System.Windows.Media;
7+
8+
namespace PrintAndSaveButtonInMainToolbar
9+
{
10+
/// <summary>
11+
/// Interaction logic for MainWindow.xaml
12+
/// </summary>
13+
public partial class MainWindow : Window
14+
{
15+
private Button printButton;
16+
public MainWindow()
17+
{
18+
InitializeComponent();
19+
}
20+
21+
private void Window_Loaded(object sender, RoutedEventArgs e)
22+
{
23+
pdfViewer.Load(@"../../../Data/PDF_Succinctly.pdf");
24+
pdfViewer.Loaded += PdfViewer_Loaded;
25+
pdfViewer.DocumentLoaded += PdfViewer_DocumentLoaded;
26+
pdfViewer.DocumentUnloaded += PdfViewer_DocumentUnloaded;
27+
28+
}
29+
30+
private void PdfViewer_DocumentUnloaded(object sender, EventArgs e)
31+
{
32+
printButton.IsEnabled = false;
33+
}
34+
35+
private void PdfViewer_DocumentLoaded(object sender, EventArgs args)
36+
{
37+
printButton.IsEnabled = true;
38+
}
39+
40+
private void PdfViewer_Loaded(object sender, RoutedEventArgs e)
41+
{
42+
DocumentToolbar toolbar = pdfViewer.Template.FindName("PART_Toolbar", pdfViewer) as DocumentToolbar;
43+
ToggleButton FileButton = (ToggleButton)toolbar.Template.FindName("PART_FileToggleButton", toolbar);
44+
45+
ContextMenu FileContextMenu = FileButton.ContextMenu;
46+
foreach (MenuItem FileMenuItem in FileContextMenu.Items)
47+
{
48+
if (FileMenuItem.Name == "PART_PrintMenuItem")
49+
FileMenuItem.Visibility = Visibility.Collapsed;
50+
}
51+
52+
printButton = new Button();
53+
printButton.Height = 25;
54+
printButton.Width = 25;
55+
System.Windows.Shapes.Path printPath = new System.Windows.Shapes.Path
56+
{
57+
Data = Geometry.Parse("F1M235.967,99.88L229.46,99.88L229.46,96.688L235.967,96.688z M229.46,84.563L235.967,84.563L235.967,86.793L229.46,86.793z M241.783,86.793L237.046,86.793L237.046,83.371L228.361,83.371L228.361,86.793L223.783,86.793L223.783,96.688L228.361,96.688L228.361,101.072L237.046,101.072L237.046,96.688L241.783,96.688z"), // Example shape
58+
Width = 20,
59+
Height = 20,
60+
Style = (Style)this.pdfViewer.FindResource("MenuIconStyle"),
61+
Stretch = Stretch.Uniform, // Set the stretch mode
62+
};
63+
printButton.Content = printPath;
64+
printButton.Style = (Style)this.pdfViewer.FindResource("newButtonStyle");
65+
printButton.Click += PrintButton_Click;
66+
printButton.ToolTip = "Print";
67+
printButton.BorderThickness = new Thickness(0);
68+
printButton.Margin = new Thickness(10, 0, 0, 0);
69+
70+
StackPanel stackPanel = (StackPanel)toolbar.Template.FindName("PART_FileMenuStack", toolbar);
71+
72+
stackPanel.Children.Insert(1, printButton);
73+
}
74+
75+
private void PrintButton_Click(object sender, RoutedEventArgs e)
76+
{
77+
pdfViewer.Print();
78+
}
79+
}
80+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<ProjectGuid>{E96FFB78-A5D6-4D68-BC54-794A5A9FE5BA}</ProjectGuid>
7+
<OutputType>WinExe</OutputType>
8+
<RootNamespace>PrintAndSaveButtonInMainToolbar</RootNamespace>
9+
<AssemblyName>PrintAndSaveButtonInMainToolbar</AssemblyName>
10+
<TargetFramework>net48</TargetFramework>
11+
<FileAlignment>512</FileAlignment>
12+
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
13+
<WarningLevel>4</WarningLevel>
14+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
15+
<Deterministic>true</Deterministic>
16+
<LangVersion>latest</LangVersion>
17+
<UseWPF>true</UseWPF>
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+
</ItemGroup>
41+
<ItemGroup>
42+
<None Include="App.config" />
43+
</ItemGroup>
44+
</Project>
Lines changed: 22 additions & 0 deletions
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}") = "PrintAndSaveButtonInMainToolbar", "PrintAndSaveButtonInMainToolbar.csproj", "{E96FFB78-A5D6-4D68-BC54-794A5A9FE5BA}"
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+
{E96FFB78-A5D6-4D68-BC54-794A5A9FE5BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{E96FFB78-A5D6-4D68-BC54-794A5A9FE5BA}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{E96FFB78-A5D6-4D68-BC54-794A5A9FE5BA}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{E96FFB78-A5D6-4D68-BC54-794A5A9FE5BA}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Lines changed: 15 additions & 0 deletions
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>
Lines changed: 22 additions & 0 deletions
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}") = "PrintAndSaveButtonInMainToolbar_NET", "PrintAndSaveButtonInMainToolbar_NET.csproj", "{B1E5F5E7-53B0-4888-A320-752A68825769}"
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+
{B1E5F5E7-53B0-4888-A320-752A68825769}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{B1E5F5E7-53B0-4888-A320-752A68825769}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{B1E5F5E7-53B0-4888-A320-752A68825769}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{B1E5F5E7-53B0-4888-A320-752A68825769}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal

0 commit comments

Comments
 (0)