Disable toolbar items
28 Sep 20212 minutes to read
To remove the default toolbar completely, use the PdfDocumentView control instead of PdfViewerControl as described in the section.
However, an individual toolbar item can also be removed from the default toolbar of PDF Viewer using the toolbar template. The following code sample explains disabling the text search tool from the default toolbar.
private void HideTextSearchTool()
{
//Get the instance of the toolbar using its template name.
DocumentToolbar toolbar = pdfViewer.Template.FindName("PART_Toolbar", pdfViewer) as DocumentToolbar;
//Get the instance of the open file button using its template name.
Button textSearchButton = (Button)toolbar.Template.FindName("PART_ButtonTextSearch", toolbar);
//Set the visibility of the button to collapsed.
textSearchButton.Visibility = System.Windows.Visibility.Collapsed;
}
NOTE
Apply the changes of hiding toolbar items, only after when the application window is loaded.
The sample project for disabling toolbar item is available in the GitHub.
Similarly, other toolbar items also can be disabled. The following table lists the template names of the rest of the toolbar items along with their respective types in the order they appear in the toolbar.
Toolbar item | Template name | Type |
---|---|---|
File tool | PART_FileToggleButton | System.Windows.Controls.Primitives.ToggleButton |
Navigation tools separator | Part_NavigationToolsSeparator | System.Windows.Shapes.Rectangle |
First page tool | PART_ButtonGoToFirstPage | System.Windows.Controls.Button |
Previous page tool | PART_ButtonGoToPreviousPage | System.Windows.Controls.Button |
Current page number tool | PART_TextCurrentPageIndex | System.Windows.Controls.TextBox |
Page count tool | PART_LabelTotalPageCount | System.Windows.Controls.TextBlock |
Next page tool | PART_ButtonGoToNextPage | System.Windows.Controls.Button |
Last page tool | PART_ButtonGoToLastPage | System.Windows.Controls.Button |
Zoom tools separator | Part_ZoomToolsSeparator_0 | System.Windows.Shapes.Rectangle |
Current zoom level tool | PART_ComboBoxCurrentZoomLevel | System.Windows.Controls.ComboBox |
Zoom in tool | PART_ButtonZoomIn | System.Windows.Controls.Button |
Zoom out tool | PART_ButtonZoomOut | System.Windows.Controls.Button |
Zoom tools separator | PART_ZoomToolsSeparator_1 | System.Windows.Shapes.Rectangle |
Fit width tool | PART_ButtonFitWidth | System.Windows.Controls.Button |
Fit page tool | PART_ButtonFitPage | System.Windows.Controls.Button |
Annotation tools separator | PART_AnnotationToolsSeparator | System.Windows.Shapes.Rectangle |
Sticky note tool | PART_StickyNote | System.Windows.Controls.Primitives.ToggleButton |
Ink tool | PART_Ink | System.Windows.Controls.Primitives.ToggleButton |
Ink eraser tool | PART_InkEraser | System.Windows.Controls.Primitives.ToggleButton |
Highlight tool | PART_Highlight | System.Windows.Controls.Primitives.ToggleButton |
Underline tool | PART_Underline | System.Windows.Controls.Primitives.ToggleButton |
Strikethrough tool | PART_Strikethrough | System.Windows.Controls.Primitives.ToggleButton |
Shapes tool | PART_Shapes | System.Windows.Controls.Primitives.ToggleButton |
Fill tool | PART_Fill | System.Windows.Controls.Primitives.ToggleButton |
Add textbox tool | PART_FreeText | System.Windows.Controls.Primitives.ToggleButton |
Text properties tool | PART_ButtonTextBoxFont | System.Windows.Controls.Button |
Separator between the annotation and cursor tools | PART_AnnotationsSeparator | System.Windows.Shapes.Rectangle |
Stamp tool | PART_Stamp | System.Windows.Controls.Primitives.ToggleButton |
Handwritten signature tool | PART_ButtonSignature | System.Windows.Controls.Button |
Select tool | PART_SelectTool | System.Windows.Controls.Primitives.ToggleButton |
Hand tool | PART_HandTool | System.Windows.Controls.Primitives.ToggleButton |
Marquee zoom tool | PART_MarqueeZoom | System.Windows.Controls.Primitives.ToggleButton |
Separator between the cursor tools and text search button | Part_CursorTools | System.Windows.Shapes.Rectangle |
Text search tool | PART_ButtonTextSearch | System.Windows.Controls.Button |
NOTE
From the v18.4.0.x onwards, the file menu items such as Open, Save, Save As, and Print are not directly present in the toolbar and they are present in the context menu of the File tools toggle button.
The following code sample explains disabling the Open tool from the menu.
private void HideOpenTool(object sender, RoutedEventArgs e)
{
//Get the instance of the toolbar using its template name.
DocumentToolbar toolbar = pdfViewer.Template.FindName("PART_Toolbar", pdfViewer) as DocumentToolbar;
//Get the instance of the file menu button using its template name.
ToggleButton FileButton = (ToggleButton)toolbar.Template.FindName("PART_FileToggleButton", toolbar);
//Get the instance of the file menu button context menu and the item collection.
ContextMenu FileContextMenu = FileButton.ContextMenu;
foreach (MenuItem FileMenuItem in FileContextMenu.Items)
{
//Get the instance of the open menu item using its template name and disable its visibility.
if (FileMenuItem.Name == "PART_OpenMenuItem")
FileMenuItem.Visibility = System.Windows.Visibility.Collapsed;
}
}
Similarly, other file menu items can be disabled. The following table lists the template names along with their respective types in the order they appear in the context menu.
Toolbar item | Template name | Type |
---|---|---|
Open tool | PART_OpenMenuItem | System.Windows.Controls.MenuItem |
Save tool | PART_SaveMenuItem | System.Windows.Controls.MenuItem |
SaveAs tool | PART_SaveAsMenuItem | System.Windows.Controls.MenuItem |
Print tool | PART_PrintMenuItem | System.Windows.Controls.MenuItem |
NOTE
The present UI design is subject to change, based on the inclusion of new features, enhancements, and user convenience.