- Display attribute
- Validation attribute
- Bindable attribute
- Editable attribute
- ReadOnly attribute
- DataType attribute
- Custom attribute
Contact Support
Data annotations in .NET MAUI DataForm (SfDataForm)
The data form supports the following attribute to handle the data, and these attributes can be accessed using the System.ComponentModel.DataAnnotation assembly.
Display attribute
Property | Details |
---|---|
Specifies the label text. | |
Specifies the group name that identifies the fields in the data form. | |
Specifies the label text. It takes higher priority than Name. | |
Specifies whether the field should be auto-generated or not. | |
Specifies the Resources File (.Resx), which is used to localize the Display attribute of Name, ShortName, GroupName, Prompt and ItemsSource values. | |
Specifies watermark text for the editor. | |
Specifies the order of field in the data form. |
[Display(Name = "First Name", GroupName = "Name", Prompt="Enter your name")]
public string FirstName { get; set; }
Validation attribute
Property | Details |
---|---|
Specifies the required minimum input string length. | |
Specifies the required maximum input string length. | |
Specifies the required data field value. | |
Specifies the required string length. | |
Specifies the enum type for the data field. |
[MinLength(5, ErrorMessage = "Password length must be greater than 5 characters")]
public string Password { get; set; }
[MaxLength(20, ErrorMessage = "Maximum password length should be less than 20")]
public string Password { get; set; }
[Required(AllowEmptyStrings = false, ErrorMessage = "Name is required")]
public string Name { get; set; }
[StringLength(20, ErrorMessage = "Name should not exceed 20 characters")]
public string Name { get; set; }
[EnumDataType(typeof(Gender), ErrorMessage = "Please select Gender")]
public Gender Gender { get; set; }
Bindable attribute
It specifies whether the field should be auto-generated or not. If bindable is set to false, the field will not be auto-generated.
[Bindable(false)]
public string Name { get; set; }
Editable attribute
It specifies whether the data field is editable or not.
[Editable(false)]
public string Name { get; set; }
ReadOnly attribute
It specifies whether the data field is read only or not.
[ReadOnly(true)]
public string Name { get; set; }
NOTE
The
ReadOnlyAttribute
takes higher priority thanEditableAttribute
DataType attribute
It specifies the data type for the field.
The Supported data types are Text, MultilineText, Date, DateTime and Time.
[DataType(DataType.MultilineText)]
public string Address { get; set; }
Custom attribute
The data form supports the following custom attribute, and these attributes can be accessed using the Syncfusion.Maui.DataForm assembly.
DataFormDisplayOptions attribute
Property | Details |
---|---|
Specifies the row span for the data form item. | |
Specifies the column span for the data form item. | |
Specifies the positive message to be shown when validation is passed. | |
Specifies whether the label should be visible or not. | |
Specifies the row order of field in the data form | |
Specifies the ItemsOrderInRow property to display multiple editors in a single row. Two items with the same RowOrder property value are placed in this row according to their ItemOrderInRow property values. |
[DataFormDisplayOptions(Rowspan = 2, ColumnSpan = 2, RowOrder = 1, ItemsOrderInRow = 0)]
public string Name { get; set; }
DataFormValueConverter attribute
Specifies the Converter type, which converts the original value in a different format or as a different value.
[DataFormValueConverter(typeof(StringToDateConverter))]
public string Name { get; set; }
DateFormDateRange attribute
Property | Details |
---|---|
Specifies the maximum date that can be selected in the date editor. | |
Specifies the minimum date that can be selected in the date editor. | |
Specifies the format of the and used in attribute. |
[DataFormDateRange(DisplayFormat="yyyy/mm/dd", MaximumDate ="2022/07/01", MaximumDate ="2022/07/07")]
public DateTime EventDate { get; set; }
NOTE