Toggle visibility of the tool bar in WPF Pdf Viewer

6 Apr 20233 minutes to read

PDF Viewer supports showing and hiding toolbar, when you feel to customize the toolbar, you can hide the default toolbar of the PDF Viewer using the ShowToolbar property. The following code example hides the default toolbar in the PDF Viewer control.

// Hide the default (top) toolbar of the PDF Viewer
pdfViewer.ShowToolbar = false;
' Hiding the default toolbar of the PDF Viewer
pdfViewer.ShowToolbar = False

Expand the Annotation toolbar by programmatically.

The annotation toolbar is a secondary toolbar of PDF Viewer control that contains a collection of annotation buttons. By default, this annotation toolbar will be collapsed. To expand annotation toolbar at runtime, the user can click show annotations button, which is present in the primary toolbar. In order to expand annotation toolbar at loading or by programmatically, the user can just enable the isChecked property in annotations button as true. The following code example shows how to expands the annotation toolbar by programmatically in the PDF Viewer control.

private void ExpandAnnotationToolbar() 
{ 
	// 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 annotation button using its template name. 
	ToggleButton annotationButton = (ToggleButton)toolbar.Template.Findname("PART_Annotations", toolbar);
	// Expand the annotation toolbar. 
	annotationButton.IsChecked = true; 
}
Private Sub ExpandAnnotationToolbar()
    ' Get the instance of the toolbar using its template name.
    Dim toolbar As DocumentToolbar = TryCast(pdfViewer.Template.Findname("PART_Toolbar", pdfViewer), DocumentToolbar)
	' Get the instance of the annotation button using its template name. 
	Dim annotationButton As ToggleButton = CType(toolbar.Template.Findname("PART_Annotations", toolbar), ToggleButton)
	' Expand the annotation toolbar. 
	annotationButton.IsChecked = True
End Sub

Hide the vertical toolbar

You can hide the vertical toolbar which is present in the left side of PDF Viewer by disabling all the items present in the toolbar. Refer to the following code to hide the vertical toolbar.

private void HideVerticalToolbar() 
{ 
	// Hides the thumbnail icon. 
	pdfViewer.ThumbnailSettings.IsVisible = false; 
	// Hides the bookmark icon. 
	pdfViewer.IsBookmarkEnabled = false; 
	// Hides the layer icon. 
	pdfViewer.EnableLayers = false; 
	// Hides the organize page icon. 
	pdfViewer.PageOrganizerSettings.IsIconVisible = false; 
	// Hides the redaction icon. 
	pdfViewer.EnableRedactionTool = false;   
	// Hides the form icon. 
	pdfViewer.FormSettings.IsIconVisible = false;
}
Private Sub HideVerticalToolbar()
    pdfViewer.ThumbnailSettings.IsVisible = False
    pdfViewer.IsBookmarkEnabled = False
    pdfViewer.EnableLayers = False
    pdfViewer.PageOrganizerSettings.IsIconVisible = False
    pdfViewer.EnableRedactionTool = False
    pdfViewer.FormSettings.IsIconVisible = False
End Sub

NOTE

The sample project for disabling top and left toolbar is available in the GitHub.