We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

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

Platform: Xamarin.Forms |
Control: SfDataForm

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

2X faster development

The ultimate Xamarin UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile