PDF Viewer Form Field Events
9 Jul 20264 minutes to read
The Syncfusion WPF PDF Viewer supports form field click events, allowing applications to detect when a user clicks on a form field. These events can be used to trigger application‑specific actions or handle basic interactions when a form field is selected.
Retrieve the form field details
WPF PDF Viewer allows form field details to be retrieved through the FormFieldClicked event of PdfViewerControl when a form field is clicked in the PDF document. The FormField property available in FormFieldClickedEventArgs must be cast to the appropriate form field type to access specific details.
The following code snippet demonstrates how to retrieve details for all supported form fields using the FormFieldClicked event.
//Wire the `FormFieldClicked` event.
pdfViewer.FormFieldClicked += PdfViewer_FormFieldClicked;
private void PdfViewer_FormFieldClicked(object sender, FormFieldClickedEventArgs args)
{
if (args.FormField is TextBox)
{
//Typecast the `FormField` property to `System.Windows.Controls.TextBox`
TextBox text = args.FormField as TextBox;
//{Insert your code here}
}
else if (args.FormField is PasswordBox)
{
//Typecast the `FormField` property to `System.Windows.Controls.PasswordBox`
PasswordBox PasstextBox = args.FormField as PasswordBox;
//{Insert your code here}
}
else if (args.FormField is ListBox)
{
//Typecast the `FormField` property to `System.Windows.Controls.ListBox`
ListBox listBox = args.FormField as ListBox;
//{Insert your code here}
}
else if (args.FormField is ComboBox)
{
//Typecast the `FormField` property to `System.Windows.Controls.ComboBox`
ComboBox comboBox = args.FormField as ComboBox;
//{Insert your code here}
}
else if (args.FormField is CheckBox)
{
//Typecast the `FormField` property to `System.Windows.Controls.CheckBox`
CheckBox checkBox = args.FormField as CheckBox;
//{Insert your code here}
}
else if (args.FormField is RadioButton)
{
//Typecast the `FormField` property to `System.Windows.Controls.RadioButton`
RadioButton radiobtn = args.FormField as RadioButton;
//{Insert your code here}
}
}Common Use Cases
Form field events can be used to:
- Track user interaction with form fields
- Update UI elements dynamically
- Trigger workflow actions based on field changes
- Enforce business rules during form editing