Activate or deactivate tools in our viewer toolbar
It’s possible to control the main toolbar to programmatically activate or deactivate specific items or behaviors.
Currently, our default toolbar buttons allow you to control:
-
InteractionMode
, which is the current interaction mode in the viewer. -
SidebarMode
, which determines which sidebar to show. -
One-off actions that don’t need a permanent (visual) activation state.
In addition, the main toolbar is completely customizable and can host custom toolbar items. Refer to the customize existing tools guide for more details.
Interaction mode
The interaction mode controls the current interaction mode of the viewer. For example, you can use it to activate or deactivate a tool, like the text annotation one:
<!-- MyPage.xaml --> ... <pspdfkit:PDFView x:Name="PDFView" Initialized="OnPDFViewInitialized" InteractionMode="{Binding SelectedInteractionMode}" /> ...
// MyPage.xaml.cs ... public void OnPDFViewInitialized(object sender, EventArgs e) { _viewModel.OnPDFViewInitialized(); } ...
// MyViewModel.cs ... private InteractionMode? _selectedInteractionMode; public InteractionMode? SelectedInteractionMode { get => _selectedInteractionMode; set { if (_selectedInteractionMode == value) { return; } _selectedInteractionMode = value; OnPropertyChanged(); } } public void OnPDFViewInitialized() { // Logic to load document. ... SelectedInteractionMode = InteractionMode.Text; } ...
As a result of activating the interaction mode, Nutrient MAUI SDK will also enable the free text annotation button in the toolbar and the corresponding annotation type toolbar.
To reset the interaction mode and deactivate the button, you can set its value to null
:
SelectedInteractionMode = null;
See the API Reference for a comprehensive list of supported interaction modes.
Sidebar mode
Similar to InteractionMode
, it’s possible to control the viewer sidebar by changing the PDFView.SidebarMode
.