Form Field Events in .NET MAUI PDF Viewer (SfPdfViewer)

17 Jul 20262 minutes to read

The SfPdfViewer exposes events that allow you to track and respond to user interactions with form fields. The following table summarizes the available events:

Event Description
FormFieldValueChanged Raised when the value of a form field changes.
FormFieldFocusChanged Raised when a text or signature field gains or loses focus.

Detect value changes

The FormFieldValueChanged event is raised whenever the value of a form field changes. You can use the OldValue and NewValue properties of FormFieldValueChangedEventArgs to read the before and after values.

Subscribe to the event in XAML:

<syncfusion:SfPdfViewer x:Name="PdfViewer"
                        FormFieldValueChanged="PdfViewer_FormFieldValueChanged"/>

Handle the event in code:

private void PdfViewer_FormFieldValueChanged(object sender, FormFieldValueChangedEventArgs e)
{
    if (e.FormField is TextFormField textFormField)
    {
        // Read the previous and current values.
        string oldText = e.OldValue?.ToString();
        string newText = e.NewValue?.ToString();
    }
}

NOTE

The OldValue and NewValue types vary by field type. For a checkbox, cast them to bool to read the checked state. For a combo box or radio button, cast them to string.

Detect focus changes

The FormFieldFocusChanged event is raised when a text or signature field gains or loses focus. This event is raised only for text and signature form fields. Use the HasFocus property of the FormFieldFocusChangedEventArgs to determine whether the field is being focused or unfocused.

Subscribe to the event in XAML:

<syncfusion:SfPdfViewer x:Name="PdfViewer"
                        FormFieldFocusChanged="PdfViewer_FormFieldFocusChanged"/>

Handle the event in code:

private void PdfViewer_FormFieldFocusChanged(object sender, FormFieldFocusChangedEventArgs e)
{
    FormField field = e.FormField;
    bool hasFocus = e.HasFocus;
}

See Also