Articles in this section
Category / Section

How to register common editor for same data type properties in Xamarin.Forms DataForm business object?

2 mins read

Xamarin DataForm allows you to use a specific editor type such as built-in supported editor or a custom editor generically to the properties of DataObject that have similar data types.

This article explains how to register a built-in editor or custom editor to the same data type in business object.

Here, DayHours is data model for dataform.

public class DayHours : INotifyPropertyChanged
{
    private int startHour;
    private int startMinutes;
 
    [Display(Name = "Start Hour")]
    public int StartHour
    {
        get
        {
            return startHour;
        }
        set
        {
            startHour = value;
            RaisePropertyChanged("StartHour");
        }
    }
    public int StartMinutes
    {
        get
        {
            return startMinutes;
        }
        set
        {
            startMinutes = value;
            RaisePropertyChanged("StartMinutes");
        }
    }
 
    public event PropertyChangedEventHandler PropertyChanged;
 
    private void RaisePropertyChanged(String Name)
    {
        if (PropertyChanged != null)
            this.PropertyChanged(this, new PropertyChangedEventArgs(Name));
    }
}

 

In the following code snippet, the “NumericUpDown” editor type has been registered generically to all int data type properties in underlying DataObject using the RegisterEditor method.

dataForm.DataObject = new DayHours();
dataForm.RegisterEditor(typeof(int), "NumericUpDown");

 

By doing this, you can avoid registering the editor type to every property in business object that needs same editor type.

dataForm.RegisterEditor("StartHour", "NumericUpDown"); 
dataForm.RegisterEditor("StartMinutes", "NumericUpDown");

 

Sample Demo: RegisterCommonEditor

You can register custom editor generically to the properties that have same data type. Here, a customer editor named as CustomSlider that have Slider as Editorview has been given. You can use this custom editor for the properties that have int data type.

 

public class CustomSliderEditor : DataFormEditor<Slider>
{
    public CustomSliderEditor(SfDataForm dataForm) : base(dataForm)
    {
 
    }
 
    protected override Slider OnCreateEditorView(DataFormItem dataFormItem)
    {
        return new Slider();
    }
 
    protected override void OnInitializeView(DataFormItem dataFormItem, Slider view)
    {
        base.OnInitializeView(dataFormItem, view);
        view.Value = 15;
        view.Minimum = 0;
        view.Maximum = 23;
        view.MaximumTrackColor = Color.Gray;
        view.MinimumTrackColor = Color.HotPink;
        view.ThumbColor = Color.HotPink;
    }
}

 

Refer to the following code example for binding DataObject and adding CustomSliderEditor as CustomEditor using the RegisterEditor method

dataForm.DataObject = new DayHours();
dataForm.RegisterEditor("Slider", new CustomSliderEditor(dataForm));
dataForm.RegisterEditor(typeof(int), "Slider");

 

Sample Demo: RegisterCommonEditor


Conclusion

I hope you enjoyed learning how to register common editor for same data type properties in Xamarin DataForm bisiness object.

You can refer to our Xamarin DataForms feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our Xamarin dataForms example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-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)
Please sign in to leave a comment
Access denied
Access denied