2X faster development
The ultimate Xamarin UI toolkit to boost your development speed.
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.
This page will automatically be redirected to the sign-in page in 10 seconds.