# 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 the `Canvas` panel 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 of `UILayerInitializeContext` provides the following API:
  * `Document`—Gets the document of the RadPdfViewer, which is of the type of `RadFixedDocument`.
  * `Owner`—Gets the owner of the UI layer, which is of the type of `IUILayerContainer`.
  * `Page`—Gets the page of the type of `RadFixedPage`.
  * `Presenter`—Gets the presenter of the type of `IFixedDocumentPresenter`.
* `Update(UILayerUpdateContext context)`—This method is raised when the UI layer is updated. The parameter of the type of `UILayerUpdateContext` provides the following API:
  * `ShouldShowSelectionMarkers`—Gets or sets whether selection markers should be shown.
  * `Viewport`—Gets the current viewport, in the type of `Rect`.
* `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**

```C#
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**

```C#
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**

```C#
public void RegisterLayer()
{
    ExtensibilityManager.RegisterLayersBuilder(new CustomUILayersBuilder());
}
```

> tip To download a runnable project with the example from this article, visit [our SDK repository](https://github.com/telerik/xaml-sdk/). You can find the example in the **PdfViewer/AddDocumentContent** folder.

## See Also

* [Custom Document Presenter](https://www.telerik.com/products/wpf/documentation/controls/radpdfviewer/customization-and-extensibility/custom-document-presenter)
* [Customize PDF Rendering](https://www.telerik.com/products/wpf/documentation/controls/radpdfviewer/customization-and-extensibility/customize-pdf-rendering)
