DataFormItem tapped by user
Hello,
Iam trying to execute a custom function when user taps an autogenerated DataFormItem.
I need to know which DataFormItem has been tapped as well as the associated PropertyInfo,
so that I can execute appropriate code after the tap.
Currently I tried to use DataFormItemManager, but the Focused event is sometimes triggered without user's interaction, that is why it is not good enough.
public class DataFormItemsManager : DataFormItemManager {
public override void InitializeDataEditor(DataFormItem dataFormItem, View editor) {
editor.Focused += (s, e) => { };
}
}
Then I tries assigning TapGestureRecognisers to the editors,
but the TapGestureRecognisers do not fire.
public override void InitializeDataEditor(DataFormItem dataFormItem, View editor) {
if (dataFormItem is DataFormTextItem || dataFormItem is DataFormMaskedTextItem) {
TapGestureRecognizer tapGestureRecognizer = new();
if (editor is Entry entry) {
tapGestureRecognizer.Tapped += (s, e) => Entry_Focused(dataFormItem, entry);
} else if (editor is SfMaskedEntry maskedEntry) {
tapGestureRecognizer.Tapped += (s, e) => MaskedEntry_Focused(dataFormItem, maskedEntry);
}
editor.GestureRecognizers.Add(tapGestureRecognizer);
}
}
How can I achieve this?
Thank you for your time.
Hi Marián,
Thank you for reaching out to us.
You can achieve your requirement by using a custom DataFormItemManager and attaching a TapGestureRecognizer to the editor view to detect when the user taps a specific DataForm field and then raise an event with the corresponding item details.
First, create a simple event-args class to pass the DataFormItem and its PropertyInfo:
|
public sealed class DataFormItemTappedEventArgs : EventArgs { public DataFormItem Item { get; } public PropertyInfo? PropertyInfo { get; } public DataFormItemTappedEventArgs(DataFormItem item, PropertyInfo? propertyInfo) { Item = item; PropertyInfo = propertyInfo; } }
|
Next, create a custom DataFormItemManager class, declare an ItemTapped event, and override the InitializeDataEditor method. Inside this method, attach a tap gesture recognizer to the editor view to detect user interactions:
|
public class DataFormItemManagerEditorExt : DataFormItemManager {
public event EventHandler<DataFormItemTappedEventArgs>? ItemTapped;
public override void InitializeDataEditor(DataFormItem dataFormItem, View editor) { var tap = new TapGestureRecognizer(); tap.Tapped += (s, e) => { ItemTapped?.Invoke(this, new DataFormItemTappedEventArgs(dataFormItem, dataFormItem.PropertyInfo)); };
// Add only once if (!editor.GestureRecognizers.Contains(tap)) editor.GestureRecognizers.Add(tap);
} }
|
Then subscribe to the ItemTapped event and assign the custom DataFormItemManager to the DataForm:
|
DataFormItemManagerEditorExt dataFormItemManager = new DataFormItemManagerEditorExt(); dataFormItemManager.ItemTapped += DataFormItemManager_ItemTapped; this.dataForm.ItemManager = dataFormItemManager;
private void DataFormItemManager_ItemTapped(object? sender, DataFormItemTappedEventArgs e) { // e.Item is the DataFormItem, e.PropertyInfo is the PropertyInfo // Execute your logic }
|
We have prepared a simple sample to demonstrate this behavior and included it for your reference. Please review the sample and let us know if you need any further assistance.
If you encounter any issues, kindly share the details of the problem along with the following information so we can analyze it and provide a suitable solution:
The LayoutType (Default, TextInputLayout) you are using in the DataForm
The target platform (Android, iOS, Windows, or macOS)
Regards,
Vidyalakshmi M.
Attachment: MAUIDataForm_f7a1abe.zip
- 1 Reply
- 2 Participants
-
MB Marián Banas
- Nov 17, 2025 10:13 AM UTC
- Nov 18, 2025 01:18 PM UTC