Toggle visibility of the tool bar in WPF Pdf Viewer
9 Jul 20264 minutes to read
PDF Viewer supports showing and hiding the toolbar. 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 = FalseExpand the annotation toolbar programmatically
The annotation toolbar is a secondary toolbar of the PDF Viewer control that contains a collection of annotation buttons. By default, this annotation toolbar will be collapsed. To expand the annotation toolbar at runtime, the user can click show annotations button, which is present in the primary toolbar. In order to expand the annotation toolbar at loading or programmatically, the user can just enable the isChecked property in the annotations button as true. The following code example shows how to expand the annotation toolbar 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 SubHide the vertical toolbar
You can hide the vertical toolbar which is present on the left side of the PDF Viewer by disabling all the items 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 SubNOTE
The sample project for disabling top and left toolbar is available in the GitHub.