New to Telerik UI for WinUI? Download free 30-day trial

Commands Support

The interactions with the document in the viewer are implemented with command descriptors. The descriptors are wrappers of predefined commands, like rotate, open file, page up/down and others.

The command descriptors are represented by implementations of the CommandDescriptorBase class. The following list contains only part of the available descriptors. Check the CommandDescriptors collection property of RadPdfViewer for a complete list of the available commands.

  • OpenCommandDescriptor
  • SaveAsCommandDescriptor
  • PageUpCommandDescriptor
  • PageDownCommandDescriptor
  • SelectAllCommandDescriptor
  • ZoomInCommandDescriptor
  • ZoomOutCommandDescriptor
  • MoveCaretToLineStartCommandDescriptor
  • MoveCaretToLineEndCommandDescriptor
  • ShowFindDialogCommandDescriptor

The descriptors can be accessed and can be executed via the CommandDescriptors property of RadPdfViewer. The associated command can be get through the Command property of the descriptor.

Executing the command of a descriptor

this.pdfViewer.CommandDescriptors.ShowFindDialogCommandDescriptor.Command.Execute(null); 
The commands can be disabled by setting the IsEnabled property of the associated descriptor to false.

Binding Command to the UI

The descriptor commands can be data bound to the Command property of UI elements, like buttons.

Bind the page down command to a button

<telerik:RadButton Content="Page Down"  
                   Command="{Binding ElementName=pdfViewer, Path=CommandDescriptors.PageDownCommandDescriptor.Command}"/> 

Override Default Command

The following example demonstrates how you can create a custom command and override the command of an existing descriptor. The example creates a custom command by inheriting from the FixedDocumentViewerCommandBase class, however, you can use any ICommand implementation.

Creating custom command

public class FitToWidthCommand : FixedDocumentViewerCommandBase 
{ 
    private const double PageMargin = 20; 
 
    public FitToWidthCommand(FixedDocumentViewerBase fixedDocumentViewerBase) 
        : base(fixedDocumentViewerBase) 
    { 
    } 
 
    public override void Execute(object parameter) 
    { 
        double width = this.Viewer.ActualWidth - 2 * PageMargin; 
        double pageWidth = this.Viewer.CurrentPage.Size.Width; 
        this.Viewer.ScaleFactor = width / pageWidth; 
    } 
} 

Creating custom command descriptors class in order to override the default commands

public class CustomCommandDescriptors : DefaultCommandDescriptors 
{ 
    private CommandDescriptor fitToWidthCommandDescriptor; 
 
    public override CommandDescriptor FitToWidthCommandDescriptor 
    { 
        get 
        { 
            if (this.fitToWidthCommandDescriptor == null) 
            { 
                this.fitToWidthCommandDescriptor = new CommandDescriptor(new FitToWidthCommand(FixedDocumentViewer)); 
            } 
            return fitToWidthCommandDescriptor; 
        } 
    } 
 
    public CustomCommandDescriptors(FixedDocumentViewerBase fixedDocumentViewerBase) 
        : base(fixedDocumentViewerBase) 
    { 
    } 
} 

Replacing the default command descriptors object

this.pdfViewer.CommandDescriptors = new CustomCommandDescriptors(this.pdfViewer); 

See Also

In this article
Not finding the help you need?