Custom UI Layer
The RadPdfViewer control comes with predefined UI layers that provide various functionalities, such as displaying pages, annotations, selection, and others. Additionally, it provides the ability to introduce custom UI layers that can be added to the control's functionality. To do so, you can create a new class that implements the IUILayer interface.
The IUILayer interface provides the following API:
UIElement—Gets theCanvaspanel that represents the UI layer.Name—Gets the name of the UI layer.Initialize(UILayerInitializeContext context)—This method is called when the UI layer is initialized. The parameter of the type ofUILayerInitializeContextprovides the following API:Document—Gets the document of the RadPdfViewer, which is of the type ofRadFixedDocument.Owner—Gets the owner of the UI layer, which is of the type ofIUILayerContainer.Page—Gets the page of the type ofRadFixedPage.Presenter—Gets the presenter of the type ofIFixedDocumentPresenter.
Update(UILayerUpdateContext context)—This method is raised when the UI layer is updated. The parameter of the type ofUILayerUpdateContextprovides the following API:ShouldShowSelectionMarkers—Gets or sets whether selection markers should be shown.Viewport—Gets the current viewport, in the type ofRect.
Clear()—This method clears the elements from the UI layer. It is called internally by RadPdfViewer when the pages are removed. For example, this may happen during updates in the control which change the currently visible pages.
Creating a custom UI layer
public class AddTextUILayer : IUILayer
{
public Canvas UIElement => throw new NotImplementedException();
public string Name => throw new NotImplementedException();
public void Clear()
{
throw new NotImplementedException();
}
public void Initialize(UILayerInitializeContext context)
{
throw new NotImplementedException();
}
public void Update(UILayerUpdateContext context)
{
throw new NotImplementedException();
}
}
Registering the custom UI layer
All of the UI layers of the RadPdfViewer control are managed by the UILayersBuilder class. To register the custom UI layers, derive from this class and override the BuildUILayersOverride method. The parameter will be of the type of IUILayerContainer that provides information about the registered UI layers.
Registering the custom UI layer
public class CustomUILayersBuilder : UILayersBuilder
{
protected override void BuildUILayersOverride(IUILayerContainer uiLayerContainer)
{
base.BuildUILayersOverride(uiLayerContainer);
uiLayerContainer.UILayers.AddAfter(DefaultUILayers.ContentElementsUILayer, new AddTextUILayer());
}
}
Registering the custom UILayersBuilder
To use the custom UILayersBuilder in the RadPdfViewer control, create a new instance of it, and pass it to the ExtensibilityManager.RegisterLayersBuilder static method.
Registering the custom UILayersBuilder
public class MainWindow : Window
{
public MainWindow()
{
ExtensibilityManager.RegisterLayersBuilder(new CustomUILayersBuilder());
InitializeComponent();
}
}
To download a runnable project with the example from this article, visit our SDK repository. You can find the example in the PdfViewer/AddDocumentContent folder.