- Tapped event
Contact Support
Gesture Events in .NET MAUI PDF Viewer (SfPdfViewer)
Tapped event
The SfPdfViewer provides a Tapped event that occurs when a tap gesture is detected in the control and allows you to perform custom actions when a tap occurs. This event provides information about the page number and position at the tapped location through the GestureEventArgs.
The following code example demonstrates how to subscribe to the Tapped event.
<syncfusion:SfPdfViewer x:Name="PdfViewer" Tapped="PdfViewer_Tapped"/>
SfPdfViewer PdfViewer = new SfPdfViewer();
PdfViewer.Tapped += PdfViewer_Tapped;
In the above example, the PdfViewer_Tapped
method is registered as the event handler for the Tapped event of the SfPdfViewer. The PdfViewer_Tapped
method will be invoked whenever a tap occurs on the PDF Viewer. You can handle the custom action in the method as demonstrated in the following code example.
private void PdfViewer_Tapped(object sender, GestureEventArgs e)
{
// Handle the tap event here.
}
GestureEventArgs
The GestureEventArgs provides information available on the tapped location and it includes the following properties.
- PageNumber – This property returns the page number on which the tap took place. The value ranges from 1 to the total number of pages in the PDF document. If the tap occurs outside of any PDF page boundaries, the result will be -1.
- PagePositon – The property returns the page’s tapped position in the PDF coordinates. The coordinates have their origin at the top-left of the page. The number of the tapped page is identified by the PageNumber property. If the tap occurs outside of any PDF page boundaries, the result will be (-1, -1).
- Position – This property returns the tapped position on the PDF Viewer control. The coordinate space starts at the top left of the control.
The following code example that demonstrates how to retrieve information from the GestureEventArgs and handle the tapped event.
private void PdfViewer_Tapped(object sender, GestureEventArgs e)
{
// To get the pointer position on the control where the tap occurred.
var pointerPosition = e.Position;
// To get the page number where the tap occurred.
var pageNumber = e.PageNumber;
// To get the page position where the tap occurred.
var pagePoistion = e.PagePosition;
// Handle the tap event here with the above information if required.
}