Data annotations in Xamarin DataForm (SfDataForm)
26 Sep 20232 minutes to read
The data form supports the following attribute, and these attributes can be accessible using System.ComponentModel.DataAnnotation
assembly.
Display attribute
Property | Details |
---|---|
Specifies the label text. | |
Specifies the group name which groups the fields in the data form. Refer to for more details. | |
Specifies the label text. It takes higher priority than Name. | |
Specifies whether the field should be auto generated or not. Refer to for more details. | |
Specifies watermark text for the editor. Refer to for more details. | |
Specifies the order of field in the data form. Refer to for more details. |
Validation attributes
Property | Details |
---|---|
MinLength | Specifies the required minimum length. Refer to for more details. |
MaxLength | Specifies the required maximum length. Refer to for more details. |
Required | Specifies the required data field value. Refer to for more details. |
Range | Specifies the maximum and minimum values. Refer to for more details. |
Bindable attribute
It specifies whether the field should be auto generated or not. Refer to here for more details.
Editable attribute
It specifies whether the data field is editable or not.
ReadOnly attribute
It specifies whether the data field is read only or not. Refer to here for more details.
EnumDataType attribute
It specifies enum type for the data field.
DataType attribute
It specifies data type for the field.
Supported data types are Text, MultilineText, Date, DateTime, Time, and Currency.
Refer to here for more details.
DisplayFormat attribute
It specifies how data fields are displayed and formatted.
Supported data types are currency, percentage, date, time.
Property | Details |
---|---|
DataFormatString | Specifies the display format of the field value. |
Editor | FormatString |
---|---|
Currency | {0:C} |
Percentage | {0:P} |
Date | {0:D} |
Time | {0:T} |
dataForm.DataObject = new ContactInfo();
public class ContactInfo
{
private int markPercentage;
[DisplayFormat(DataFormatString ="{0:P}")]
public String MarkPercentage
{
get
{
return markPercentage;
}
set
{
markPercentage = value;
}
}
}
CustomDataType attribute
The Percent data type is supported. Refer to here for more details.
Custom attribute
The data form supports the following custom attribute, and these attributes can be accessible using Syncfusion.SfDataForm.XForms
.
DisplayOptions attribute
Property | Details |
---|---|
Specifies the row span for the data form item. Refer to for more details. | |
Specifies the column span for the data form item. Refer to for more details. | |
Specifies positive message to be shown when validation is passed. Refer to for more details. | |
Specifies the image source for loading image instead of label. Refer to for more details. | |
Specifies whether the label should be visible or not. Refer to for more details. |
Converter attribute
Property | Details |
---|---|
Specifies the Converter type which converts the original value in different format or as different value. Refer to here for more details. |
DateRange attribute
Property | Details |
---|---|
Specifies the required minimum year. | |
Specifies the required minimum month. | |
Specifies the required minimum day. | |
Specifies the required maximum year. | |
Specifies the required maximum month. | |
Specifies the required maximum day. |
Refer to here for more details.