Articles in this section

How to add a custom picker editor in .NET MAUI DataForm (SfDataForm)?

In the Syncfusion® .NET MAUI DataForm, you can enhance the data form by integrating a custom picker editor. Follow the steps below to achieve this customization.

C#

You can register the custom editor for a specific property using the RegisterEditor method.

protected override void OnAttachedTo(SfDataForm dataForm)
{
   base.OnAttachedTo(dataForm);
   if (dataForm != null)
   {
       dataForm.RegisterEditor("Courses", new CustomPicker(dataForm));
   }
}

C#

You can customize the Picker editor using the CreateEditorView, CommitValue and UpdateReadOnly methods of the IDataFormEditor interface.

public class CustomPicker : IDataFormEditor
{
   private SfDataForm customDataForm;

   public CustomPicker(SfDataForm customDataForm)
   {
       this.customDataForm = customDataForm;
   }

   public View CreateEditorView(DataFormItem dataFormItem)
   {
       Picker inputView = new Picker
       {
           BackgroundColor = Colors.GhostWhite,
           ItemsSource = new List<string>
           {
               "SAP",
               "AWS",
               ".NET"
           }
       };

       dataFormItem.Background = Colors.CadetBlue;
       dataFormItem.LabelText = dataFormItem.FieldName;
       dataFormItem.LabelTextStyle = new DataFormTextStyle
       {
           TextColor = Colors.Black,
           FontSize = 14,
           FontAttributes = FontAttributes.Bold,
       };

       return inputView;
   }

   public void CommitValue(DataFormItem dataFormItem, View view)
   {
       // Logic to commit the value from picker
   }

   public void UpdateReadyOnly(DataFormItem dataFormItem)
   {
       // Logic to handle read-only state
   }
}

Output:

CustomPickerEditor.png

Conclusion:

I hope you enjoyed learning how to add a custom picker editor in the .NET MAUI DataForm (SfDataForm).

Refer to our .NET MAUI DataForm feature tour page for its other groundbreaking feature representations. You can also explore our .NET MAUI DataForm documentation to understand how to present and manipulate data.

Check out our .NET MAUI components from the License and Downloads page for current customers. If you are new to Syncfusion®, try our 30-day free trial to check out our .NET MAUI DataForm and other .NET MAUI components.

Please let us know in the following comments section if you have any queries or require clarification. Contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied