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

Source Exception Handling

In certain cases RadPdfViewer will not be able to load the passed Pdf document - it can be due to invalid stream/inaccessible URL or some invalid data in the document itself. RadPdfViewer provides a way to catch these cases through its SourceException event. In addition, you could show a user-friendly message to the users through SourceExceptionTemplate.

Check the example below which shows how to use the RadPdfViewer API for handling source exceptions.

First, define RadPdfViewer control and apply a SourceExceptionTemplate. The snippet below demonstrates a sample template with only one Label which holds the message.

<telerikPdfViewer:RadPdfViewer x:Name="pdfViewer" SourceException="PdfViewerSourceException">
            <Label Text="Sorry, something with loading the pdf document went wrong." 
                   LineBreakMode="WordWrap" />

Where the telerikPdfViewer namespace is the following:


And here is the SourceException event handler:

private void PdfViewerSourceException(object sender, SourceExceptionEventArgs e)
    var error = e.Exception.Message;

Check below how the defined SourceTemplateException looks:

PdfViewer SourceException

A sample SourceExceptionTemplate example can be found in the PdfViewer/Features folder of the SDK Samples Browser application.

See Also

In this article