Articles in this section

How to add custom image editor in Xamarin.iOS DataForm

DataForm allows you to add the custom editor. This article explains adding custom image editor in Xamarin iOS DataForm.

 

Here, the Image data field is loaded as custom image editor.

 

ContactForm.cs
 
    public class ContactForm
    {
 
        [DisplayOptions(ShowLabel = false, RowSpan =5)]
        public string Image { get; set; }
 
        [DisplayOptions(ColumnSpan =2)]
        [Display(ShortName = "Name")]
        public string Name { get; set; } = "John";
 
        [DisplayOptions(ColumnSpan = 2)]
        [Display(Name = "Contact Number")]
        public string Number { get; set; }
 
        [DisplayOptions(ColumnSpan = 2)]
        public string Email { get; set; }
 
        [DisplayOptions(ColumnSpan = 2)]
        public string Address { get; set; }
 
        [DisplayOptions(ColumnSpan = 2)]
        [DataType(DataType.Date)]
        [Display(Name = "Birth Date")]
        public DateTime? BirthDate { get; set; }
 
    }
   

By passing custom view in DataFormEditor class, you can add custom editor in data form. Refer to this DataForm user guide documentation for creating a new custom editor.

 

Here, the UIImageView is loaded as custom view.

 

 
    public class DataFormCustomImageEditor : DataFormEditor<UIImageView>
    {
        public DataFormCustomImageEditor(SfDataForm dataForm) : base(dataForm)
        {
        }
 
        protected override UIImageView OnCreateEditorView()
        {
            return new UIImageView();
        }
        protected override void OnInitializeView(DataFormItem dataFormItem, UIImageView view)
        {
            base.OnInitializeView(dataFormItem, view);
            view.Image =  UIImage.FromFile("Person.png");
        }
    }
 

 

Refer to the following code example for binding DataObject and adding custom editor(Image) as CustomEditor using the RegisterEditor method in DataForm.

 

 
            dataForm.DataObject = new ContactForm();
            dataForm.RegisterEditor("ImageEditor", new DataFormCustomImageEditor(dataForm));
            dataForm.RegisterEditor("Image", "ImageEditor");

 

Example: DataFormCustomImageEditor

 

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