How to Get the X and Y Coordinates with Respect to WPF PdfViewer?
You can get the coordinates of mouse pointer with respect to WPF PDF Viewer control by using Mouse_Up event.
You can refer to the following steps
Step 1: Add the following code in the MainWindow.xaml.
XAML
<Window x:Class="FindCoordinatesWpf.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" xmlns:syncfusion="clr-namespace:Syncfusion.Windows.PdfViewer;assembly=Syncfusion.PdfViewer.WPF" Title="MainWindow" Height="350" Width="525" WindowState="Maximized"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="5*"/> <ColumnDefinition Width="1*"/> </Grid.ColumnDefinitions> <syncfusion:PdfViewerControl x:Name="PdfViewer" Grid.Column="0"/> <GroupBox VerticalAlignment="Center" Grid.Column="1" Margin="20"> <GroupBox.Header> <TextBlock Text="Coordinates" FontSize="16" FontWeight="Bold"></TextBlock> </GroupBox.Header> <Grid> <Grid.RowDefinitions> <RowDefinition></RowDefinition> <RowDefinition></RowDefinition> </Grid.RowDefinitions> <StackPanel Orientation="Horizontal" Grid.Row="0"> <Label Content="X : " FontSize="16" Margin="20,10,0,10"/> <Label x:Name="xLabel" FontSize="16" Margin="0,10,0,10"/> </StackPanel> <StackPanel Orientation="Horizontal" Grid.Row="1"> <Label Content="Y : " FontSize="16" Margin="20,10,0,10"/> <Label x:Name="yLabel" FontSize="16" Margin="0,10,0,10"/> </StackPanel> </Grid> </GroupBox> </Grid> </Window>
Step 2: Add the below code snippet in the MainWindow.xaml.cs
C#
using System.Windows; using System.Windows.Input; namespace FindCoordinatesWpf { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); PdfViewer.Load("../../Data/GIS Succinctly.pdf"); PdfViewer.MouseUp += PdfViewer_MouseUp; } private void PdfViewer_MouseUp(object sender, MouseButtonEventArgs e) { System.Drawing.Point position = new System.Drawing.Point { X = (int)e.GetPosition(PdfViewer).X, Y = (int)e.GetPosition(PdfViewer).Y }; //Displays the x and y coordinates xLabel.Content = position.X; yLabel.Content = position.Y; } } }
Conclusion
I hope you enjoyed learning about how to get the x and y coordinates with respect to WPF PdfViewer.
You can refer to our WPF PDF Viewer feature tour page to know about its other groundbreaking feature representations. You can also explore our WPF PDF Viewer documentation to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!