Class SfDataForm
Initializes a new instance of the SfDataForm class.
Implements
Inherited Members
Namespace: Syncfusion.Maui.DataForm
Assembly: Syncfusion.Maui.DataForm.dll
Syntax
public class SfDataForm : SfView, IDrawableLayout, IDrawable, IAbsoluteLayout, ILayout, IView, IElement, ITransform, IContainer, IList<IView>, ICollection<IView>, IEnumerable<IView>, IEnumerable, ISafeAreaView, IPadding, ICrossPlatformLayout, IVisualTreeElement, ISemanticsProvider, IDataFormItemInfo, IDataFormInfo, IParentThemeElement, IThemeElement
Remarks
The DataForm control is used to manage data and develop various forms such as login, reservation, data entry and so on.
Examples
The following code demonstrates, how to bind DataObject
and populate editors in the dataform control.
<dataForm:SfDataForm x:Name="dataForm"
DataObject="{Binding ContactsInfo}"
AutoGenerateItems="True">
<dataForm:SfDataForm.BindingContext>
<local:DataFormViewModel />
</dataForm:SfDataForm.BindingContext>
</dataForm:SfDataForm>
# [C#](#tab/tabid-2)
public class DataFormViewModel
{
public ContactsInfo ContactsInfo { get;set; }
}
# [C#](#tab/tabid-3)
public class ContactsInfo
{
public string FirstName { get; set; }
public string MiddleName { get; set; }
public string LastName { get; set; }
public string ContactNumber { get; set; }
public string Email { get; set; }
public string Address { get; set; }
public DateTime? BirthDate { get; set; }
public string GroupName { get; set; }
}
# [C#](#tab/tabid-4)
this.dataForm.DataObject = new DataFormViewModel().ContactsInfo;
Constructors
SfDataForm()
Initializes a new instance of the SfDataForm class.
Declaration
public SfDataForm()
Fields
AutoGenerateItemsProperty
Identifies the AutoGenerateItems dependency property.
Declaration
public static readonly BindableProperty AutoGenerateItemsProperty
Field Value
Type | Description |
---|---|
Microsoft.Maui.Controls.BindableProperty | The identifier for AutoGenerateItems dependency property. |
ColumnCountProperty
Identifies the ColumnCount dependency property.
Declaration
public static readonly BindableProperty ColumnCountProperty
Field Value
Type | Description |
---|---|
Microsoft.Maui.Controls.BindableProperty | The identifier for ColumnCount dependency property. |
CommitModeProperty
Identifies the CommitMode dependency property.
Declaration
public static readonly BindableProperty CommitModeProperty
Field Value
Type | Description |
---|---|
Microsoft.Maui.Controls.BindableProperty | The identifier for CommitMode dependency property. |
DataObjectProperty
Identifies the DataObject dependency property.
Declaration
public static readonly BindableProperty DataObjectProperty
Field Value
Type | Description |
---|---|
Microsoft.Maui.Controls.BindableProperty | The identifier for DataObject dependency property. |
DefaultLayoutSettingsProperty
Identifies the DefaultLayoutSettings dependency property.
Declaration
public static readonly BindableProperty DefaultLayoutSettingsProperty
Field Value
Type | Description |
---|---|
Microsoft.Maui.Controls.BindableProperty | The identifier for DefaultLayoutSettings dependency property. |
EditorTextStyleProperty
Identifies the EditorTextStyle dependency property.
Declaration
public static readonly BindableProperty EditorTextStyleProperty
Field Value
Type | Description |
---|---|
Microsoft.Maui.Controls.BindableProperty | The identifier for EditorTextStyle dependency property. |
ErrorLabelTextStyleProperty
Identifies the ErrorLabelTextStyle dependency property.
Declaration
public static readonly BindableProperty ErrorLabelTextStyleProperty
Field Value
Type | Description |
---|---|
Microsoft.Maui.Controls.BindableProperty | The identifier for ErrorLabelTextStyle dependency property. |
GroupHeaderTemplateProperty
Identifies the GroupHeaderTemplate dependency property.
Declaration
public static readonly BindableProperty GroupHeaderTemplateProperty
Field Value
Type | Description |
---|---|
Microsoft.Maui.Controls.BindableProperty | The identifier for GroupHeaderTemplate dependency property. |
IsReadOnlyProperty
Identifies the IsReadOnly dependency property.
Declaration
public static readonly BindableProperty IsReadOnlyProperty
Field Value
Type | Description |
---|---|
Microsoft.Maui.Controls.BindableProperty | The identifier for IsReadOnly dependency property. |
ItemManagerProperty
Identifies the ItemManager dependency property.
Declaration
public static readonly BindableProperty ItemManagerProperty
Field Value
Type | Description |
---|---|
Microsoft.Maui.Controls.BindableProperty | The identifier for ItemManager dependency property. |
ItemsProperty
Identifies the Items dependency property.
Declaration
public static readonly BindableProperty ItemsProperty
Field Value
Type | Description |
---|---|
Microsoft.Maui.Controls.BindableProperty | The identifier for Items dependency property. |
ItemsSourceProviderProperty
Identifies the ItemsSourceProvider dependency property.
Declaration
public static readonly BindableProperty ItemsSourceProviderProperty
Field Value
Type | Description |
---|---|
Microsoft.Maui.Controls.BindableProperty | The identifier for ItemsSourceProvider dependency property. |
LabelTextStyleProperty
Identifies the LabelTextStyle dependency property.
Declaration
public static readonly BindableProperty LabelTextStyleProperty
Field Value
Type | Description |
---|---|
Microsoft.Maui.Controls.BindableProperty | The identifier for LabelTextStyle dependency property. |
LayoutTypeProperty
Identifies the LayoutType dependency property.
Declaration
public static readonly BindableProperty LayoutTypeProperty
Field Value
Type | Description |
---|---|
Microsoft.Maui.Controls.BindableProperty | The identifier for LayoutType dependency property. |
TextInputLayoutSettingsProperty
Identifies the TextInputLayoutSettings dependency property.
Declaration
public static readonly BindableProperty TextInputLayoutSettingsProperty
Field Value
Type | Description |
---|---|
Microsoft.Maui.Controls.BindableProperty | The identifier for TextInputLayoutSettings dependency property. |
ValidationModeProperty
Identifies the ValidationMode dependency property.
Declaration
public static readonly BindableProperty ValidationModeProperty
Field Value
Type | Description |
---|---|
Microsoft.Maui.Controls.BindableProperty | The identifier for ValidationMode dependency property. |
ValidMessageLabelTextStyleProperty
Identifies the ValidMessageLabelTextStyle dependency property.
Declaration
public static readonly BindableProperty ValidMessageLabelTextStyleProperty
Field Value
Type | Description |
---|---|
Microsoft.Maui.Controls.BindableProperty | The identifier for ValidMessageLabelTextStyle dependency property. |
Properties
AutoGenerateItems
Gets or sets a value indicating whether auto generate the DataFormItems in the data form.
Declaration
public bool AutoGenerateItems { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean | The default value is |
Remarks
The custom dataform Items can be generated by setting AutoGenerateItems to false/>.
Examples
The below examples shows, how to set the AutoGenerateItems to the SfDataForm.
See Also
ColumnCount
Gets or sets the value representing the number of editors to be arranged per row in the data form.
Declaration
public int ColumnCount { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 | The default value is |
Examples
The below examples shows, how to set the ColumnCount to the SfDataForm.
<dataForm:SfDataForm x:Name="dataForm"
AutoGenerateItems="False"
ColumnCount="2">
<dataForm:SfDataForm.Items>
<dataForm:DataFormTextItem FieldName="First Name"/>
<dataForm:DataFormTextItem FieldName="Last Name"/>
<dataForm:DataFormTextItem FieldName="Contact Number"/>
<dataForm:DataFormDateItem FieldName="Date of Birth"/>
<dataForm:DataFormTextItem FieldName="Email"/>
<dataForm:DataFormMultilineItem FieldName="Address"/>
</dataForm:SfDataForm.Items>
</dataForm:SfDataForm>
See Also
CommitMode
Gets or sets the value that determines when to commit values that users enter in the data form’s editors to the bound data object.
Declaration
public DataFormCommitMode CommitMode { get; set; }
Property Value
Type | Description |
---|---|
DataFormCommitMode | The default value is LostFocus. |
Remarks
The CommitMode property specifies when input values should be committed to the underlying data object. The following modes are available:
- The PropertyChanged - a value is committed after changes.
- The LostFocus - a value is committed when the editor loses focus (a user taps outside the editor or presses Enter on a device’s keyboard).
- The Manual - a value is committed when the Commit() method is called.
Examples
The below examples shows, how to set the CommitMode to the SfDataForm.
<dataForm:SfDataForm x:Name="dataForm"
CommitMode="PropertyChanged"
DataObject="{Binding ContactsInfo}">
<dataForm:SfDataForm.BindingContext>
<local:DataFormViewModel />
</dataForm:SfDataForm.BindingContext>
</dataForm:SfDataForm>
DataObject
Gets or sets the value which is used to set the editors to the data form.
Declaration
public object DataObject { get; set; }
Property Value
Type |
---|
System.Object |
Remarks
The data object DataObject value to view or edit the data form properties, and the data form generates the editors and labels from the public properties of the data object. This property is applicable to only when the AutoGenerateItems property is set to true.
Examples
The below examples shows, how to set the editors to the DataObject in the SfDataForm.
<dataForm:SfDataForm x:Name="dataForm"
DataObject="{Binding ContactsInfo}">
<dataForm:SfDataForm.BindingContext>
<local:DataFormViewModel />
</dataForm:SfDataForm.BindingContext>
</dataForm:SfDataForm>
See Also
DefaultLayoutSettings
Gets or sets the settings to customize default layout (Holds label and editor) settings.
Declaration
public DataFormDefaultLayoutSettings DefaultLayoutSettings { get; set; }
Property Value
Type | Description |
---|---|
DataFormDefaultLayoutSettings | The default value of LabelPosition is Left, LabelWidth is "(DataFormItemLength(0.4, DataFormItemLengthUnitType.Star))", and EditorWidth is "(DataFormItemLength(0.4, DataFormItemLengthUnitType.Star))". |
Remarks
The DefaultLayoutSettings property takes precedence when explicitly defined.
Examples
The below examples shows, how to set the DefaultLayoutSettings to the SfDataForm.
<dataForm:SfDataForm x:Name="dataForm">
<dataForm:SfDataForm.DefaultLayoutSettings>
<dataForm:DataFormDefaultLayoutSettings
LabelPosition = "Top"/>
</dataForm:SfDataForm.DefaultLayoutSettings>
</dataForm:SfDataForm>
See Also
EditorTextStyle
Gets or sets the style of editor text, that used to customize the text color, font, font size, font family and font attributes.
Declaration
public DataFormTextStyle EditorTextStyle { get; set; }
Property Value
Type | Description |
---|---|
DataFormTextStyle | The default value of TextColor is Microsoft.Maui.Graphics.Colors.Black, FontSize is 16, FontFamily is null, FontAttributes is Microsoft.Maui.Controls.FontAttributes.None. |
Remarks
The EditorTextStyle property takes precedence when explicitly defined.
Examples
The below examples shows, how to set the EditorTextStyle to the SfDataForm.
See Also
ErrorLabelTextStyle
Gets or sets the style of error label text, that used to customize the text color, font, font size, font family and font attributes.
Declaration
public DataFormTextStyle ErrorLabelTextStyle { get; set; }
Property Value
Type | Description |
---|---|
DataFormTextStyle | The default value of TextColor is Microsoft.Maui.Graphics.Colors.Red, FontSize is 12, FontFamily is null, FontAttributes is Microsoft.Maui.Controls.FontAttributes.None. |
Remarks
The ErrorLabelTextStyle property takes precedence when explicitly defined.
Examples
The below examples shows, how to set the ErrorLabelTextStyle to the SfDataForm.
See Also
GroupHeaderTemplate
Gets or sets the group header template.
Declaration
public DataTemplate GroupHeaderTemplate { get; set; }
Property Value
Type |
---|
Microsoft.Maui.Controls.DataTemplate |
IsReadOnly
Gets or sets a value indicating whether editors are enabled for editing.
Declaration
public bool IsReadOnly { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean | The default value is |
Remarks
The IsReadOnly property takes precedence when explicitly defined. By setting IsReadOnly in AutoGenerating DataFormItem, editors can be enabled or disabled for a specific item.
Examples
The below examples shows, how to set the IsReadOnly to the SfDataForm.
See Also
ItemManager
Gets or sets the interface that provide method to get or set the value from or to the dictionary and customize the editor.
Declaration
public DataFormItemManager ItemManager { get; set; }
Property Value
Type |
---|
DataFormItemManager |
Examples
The below example shows, how to set ItemManger to the SfDataForm.
Items
Gets or sets the value which used to set the DataFormViewItem collection in the SfDataForm.
Declaration
public ObservableCollection<DataFormViewItem> Items { get; set; }
Property Value
Type |
---|
System.Collections.ObjectModel.ObservableCollection<DataFormViewItem> |
Remarks
The property is applicable to only when the AutoGenerateItems property is set to false.
Examples
The below examples shows, how to set the custom editors to the Items in the data form.
<dataForm:SfDataForm x:Name="dataForm"
AutoGenerateItems="False">
<dataForm:SfDataForm.Items>
<dataForm:DataFormTextItem FieldName="First Name"/>
<dataForm:DataFormTextItem FieldName="Last Name"/>
<dataForm:DataFormTextItem FieldName="Contact Number"/>
<dataForm:DataFormDateItem FieldName="Date of Birth"/>
<dataForm:DataFormTextItem FieldName="Email"/>
<dataForm:DataFormMultilineItem FieldName="Address"/>
</dataForm:SfDataForm.Items>
</dataForm:SfDataForm>
See Also
ItemsSourceProvider
Gets or sets the value to get the source for picker type editors.
Declaration
public IDataFormSourceProvider ItemsSourceProvider { get; set; }
Property Value
Type | Description |
---|---|
IDataFormSourceProvider | The default value is |
Examples
The below examples shows, how to set the ItemsSourceProvider to the SfDataForm.
<dataForm:SfDataForm x:Name="dataForm"
DataObject="{Binding ContactsInfo}">
<dataForm:SfDataForm.BindingContext>
<local:DataFormViewModel />
</dataForm:SfDataForm.BindingContext>
</dataForm:SfDataForm>
LabelTextStyle
Gets or sets the style of label text, that used to customize the text color, font, font size, font family and font attributes.
Declaration
public DataFormTextStyle LabelTextStyle { get; set; }
Property Value
Type | Description |
---|---|
DataFormTextStyle | The default value of TextColor is Microsoft.Maui.Graphics.Colors.Black, FontSize is 16, FontFamily is null, FontAttributes is Microsoft.Maui.Controls.FontAttributes.None. |
Remarks
The LabelTextStyle property takes precedence when explicitly defined.
Examples
The below examples shows, how to set the LabelTextStyle to the SfDataForm.
See Also
LayoutType
Gets or sets layout option.
Declaration
public DataFormLayoutType LayoutType { get; set; }
Property Value
Type | Description |
---|---|
DataFormLayoutType | The default value is |
Examples
The below example shows, how to set LayoutType to the SfDataForm.
<dataForm:SfDataForm x:Name="dataForm"
LayoutType="Default"
DataObject="{Binding ContactsInfo}">
<dataForm:SfDataForm.BindingContext>
<local:DataFormViewModel />
</dataForm:SfDataForm.BindingContext>
</dataForm:SfDataForm>
TextInputLayoutSettings
Gets or sets text input layout settings.
Declaration
public TextInputLayoutSettings TextInputLayoutSettings { get; set; }
Property Value
Type | Description |
---|---|
TextInputLayoutSettings | The default value of ContainerType is Outlined and ShowHelperText is |
Remarks
The TextInputLayoutSettings is applicable only when LayoutType or LayoutType is TextInputLayout. The TextInputLayoutSettings property takes precedence when explicitly defined.
Examples
The below example shows, how to set TextInputLayoutSettings to the SfDataForm.
<dataForm:SfDataForm x:Name="dataForm"
LayoutType="TextInputLayout"
DataObject="{Binding ContactsInfo}">
<dataForm:SfDataForm.BindingContext>
<local:DataFormViewModel />
</dataForm:SfDataForm.BindingContext>
<dataForm:SfDataForm.TextInputLayoutSettings>
<dataForm:TextInputLayoutSettings
ContainerType="Outlined"/>
</dataForm:SfDataForm.TextInputLayoutSettings>
</dataForm:SfDataForm>
See Also
ValidationMode
Gets or sets a value that denotes when the user input should be validated based on IDataErrorInfo and ValidationAttributes.
Declaration
public DataFormValidationMode ValidationMode { get; set; }
Property Value
Type | Description |
---|---|
DataFormValidationMode | The default value is LostFocus. |
Remarks
The ValidationMode property specifies when the data form validates the user input. The following modes are supported:
- The LostFocus — the form validates a data field when an editor loses focus.
- The PropertyChanged — the form validates a data field when its value changes.
- The Manual — the form validates data fields when the Validate() method is called. You can also call the Validate(List<String>) method to validate a specific data field.
Examples
The below examples shows, how to set the ValidationMode to the SfDataForm.
<dataForm:SfDataForm x:Name="dataForm"
ValidationMode="PropertyChanged"
DataObject="{Binding ContactsInfo}">
<dataForm:SfDataForm.BindingContext>
<local:DataFormViewModel />
</dataForm:SfDataForm.BindingContext>
</dataForm:SfDataForm>
ValidMessageLabelTextStyle
Gets or sets the style of validation label text, that used to customize the text color, font, font size, font family and font attributes.
Declaration
public DataFormTextStyle ValidMessageLabelTextStyle { get; set; }
Property Value
Type | Description |
---|---|
DataFormTextStyle | The default value of TextColor is Microsoft.Maui.Graphics.Colors.Green, FontSize is 12, FontFamily is null, FontAttributes is Microsoft.Maui.Controls.FontAttributes.None. |
Remarks
The ValidMessageLabelTextStyle property takes precedence when explicitly defined.
Examples
The below examples shows, how to set the ValidMessageLabelTextStyle to the SfDataForm.
See Also
Methods
Commit()
Method to commit all properties underlying data object from the editor view.
Declaration
public void Commit()
Examples
The below examples shows, how to set the Commit method to the data form.
See Also
GetDataFormGroupItem(String)
Gets the DataFormGroupItem.
Declaration
public DataFormGroupItem GetDataFormGroupItem(string groupName)
Parameters
Type | Name | Description |
---|---|---|
System.String | groupName | The group name. |
Returns
Type | Description |
---|---|
DataFormGroupItem | The DataFormGroupItem with specified group name. |
Examples
The below examples shows, how to set the GetDataFormGroupItem method to the data form.
See Also
GetDataFormItem(String)
Gets the DataFormItem.
Declaration
public DataFormItem GetDataFormItem(string propertyName)
Parameters
Type | Name | Description |
---|---|---|
System.String | propertyName | The property name. |
Returns
Type | Description |
---|---|
DataFormItem | The DataFormItem with specified property name. |
Examples
The below examples shows, how to set the GetDataFormItem method to the data form.
See Also
MeasureContent(Double, Double)
This method will invoke on measure.
Declaration
protected override Size MeasureContent(double widthConstraint, double heightConstraint)
Parameters
Type | Name | Description |
---|---|---|
System.Double | widthConstraint | The width. |
System.Double | heightConstraint | The height. |
Returns
Type | Description |
---|---|
Microsoft.Maui.Graphics.Size | The size. |
Overrides
OnBindingContextChanged()
Invokes on the binding context of the view changed.
Declaration
protected override void OnBindingContextChanged()
Overrides
RegisterEditor(String, DataFormEditorType)
Registers editor for property name.
Declaration
public void RegisterEditor(string propertyName, DataFormEditorType editor)
Parameters
Type | Name | Description |
---|---|---|
System.String | propertyName | The propertyName to have editor. |
DataFormEditorType | editor | The editor that loaded for property name. |
Examples
The below examples shows, how to set the RegisterEditor method to the data form.
See Also
RegisterEditor(String, IDataFormEditor)
Registers editor for custom editor.
Declaration
public void RegisterEditor(string propertyName, IDataFormEditor editor)
Parameters
Type | Name | Description |
---|---|---|
System.String | propertyName | The propertyName to have editor. |
IDataFormEditor | editor | The custom editor that loaded for property name. |
Examples
The below examples shows, how to set the RegisterEditor method to the data form.
See Also
RegisterEditor(Type, DataFormEditorType)
Registers editor for property type.
Declaration
public void RegisterEditor(Type type, DataFormEditorType editor)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type | The type to have editor. |
DataFormEditorType | editor | The editor that loaded for type. |
Examples
The below examples shows, how to set the RegisterEditor method to the data form.
See Also
ScrollTo(String)
Scrolls to specific editor in data form.
Declaration
public void ScrollTo(string fieldName)
Parameters
Type | Name | Description |
---|---|---|
System.String | fieldName | The name of the editor field. |
UpdateEditor(String)
Updates the value of the specific property in corresponding editor.
Declaration
public void UpdateEditor(string propertyName)
Parameters
Type | Name | Description |
---|---|---|
System.String | propertyName | The property name. |
Validate()
Validates all the fields of Items.
Declaration
public bool Validate()
Returns
Type | Description |
---|---|
System.Boolean | True if all the fields are valid, otherwise false. |
Examples
The below examples shows, how to set the Validate method to the data form.
See Also
Validate(List<String>)
Validates the specified properties.
Declaration
public bool Validate(List<string> propertyName)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.List<System.String> | propertyName | The list of property names. |
Returns
Type | Description |
---|---|
System.Boolean | True if all the specified fields are valid, otherwise false. |
Examples
The below examples shows, how to set the Validate method to the data form.
See Also
Events
GenerateDataFormItem
Occurs during the generation of data form item in the data form when AutoGenerateItems is true.
Declaration
public event EventHandler<GenerateDataFormItemEventArgs> GenerateDataFormItem
Event Type
Type |
---|
System.EventHandler<GenerateDataFormItemEventArgs> |
Examples
The following code demonstrates, how to use the SfDataForm's generate data form item event.
<dataForm:SfDataForm x:Name="dataForm"
AutoGenerateItems="True"
GenerateDataFormItem="OnDataFormGenerateDataFormItem">
</dataForm:SfDataForm>
See Also
ValidateForm
Occurs when Manual to get the invalid DataFormItem’s details.
Declaration
public event EventHandler<DataFormValidateFormEventArgs> ValidateForm
Event Type
Type |
---|
System.EventHandler<DataFormValidateFormEventArgs> |
Examples
The following code demonstrates, how to use the SfDataForm's validate form event.
<dataForm:SfDataForm x:Name="dataForm"
ValidateForm="OnDataFormValidateForm">
</dataForm:SfDataForm>
See Also
ValidateProperty
Occurs when SfDataForm validates the user input.
Declaration
public event EventHandler<DataFormValidatePropertyEventArgs> ValidateProperty
Event Type
Type |
---|
System.EventHandler<DataFormValidatePropertyEventArgs> |
Examples
The following code demonstrates, how to use the SfDataForm's validate property event.
<dataForm:SfDataForm x:Name="dataForm"
AutoGenerateItems="True"
ValidateProperty="OnDataFormValidateProperty">
</dataForm:SfDataForm>