This example demonstrates how to use the DataFormView
control to implement a contact edit form. To edit the user avatar, you can use the ImageEdit
control.
-
Specify the
DataFormView.DataObject
property to bind aDataFormView
to an object. -
Use a
DataFormView
editor'sFieldName
property to bind the editor to a view model's property:<dxdf:DataFormTextItem FieldName="FirstName" .../>
-
Call the
DataFormView.Commit
method to validate input values and send changes to the data source. -
DataFormView
supports validation events and attributes. The following code uses a validation event forEmail
values:private void ValidateCustomerProperties(object sender, DevExpress.Maui.DataForm.DataFormPropertyValidationEventArgs e) { if (e.PropertyName == "Email" && e.NewValue != null) { MailAddress res; if (!MailAddress.TryCreate((string)e.NewValue, out res)) { e.HasError = true; e.ErrorText = "Invalid email"; } } }
The following code snippet defines validation attributes for
FirstName
andLastName
properties:public class Customer { [Required(ErrorMessage = "First Name cannot be empty")] public string FirstName //... [Required(ErrorMessage = "Last Name cannot be empty")] public string LastName //... }
-
DataFormView
automatically aligns its editors. You can customize the color and width of editor labels:<dxdf:DataFormView EditorLabelColor="{StaticResource Primary}" EditorLabelWidth="40">
-
Embedded
DataFormView
's editors contain customization options such asLabelIcon
,InplaceLabelText
,LabelText
, andIsInplaceLabelFloating
. -
You can use the
LabelIcon
property to divide editors into visual groups.<dxdf:DataFormView ...> <dxdf:DataFormTextItem FieldName="FirstName" LabelIcon="editorsname" .../> <dxdf:DataFormTextItem FieldName="LastName" .../> </dxdf:DataFormView>
-
If an editor's
LabelIcon
property is not specified,DataFormView
displays the bound property's name in the editor's label area. You can set the editor'sLabelIcon
property to an empty string to hide this text.<dxdf:DataFormTextItem FieldName="LastName" LabelText="" InplaceLabelText="Last Name" .../>
-
DataFormView
items support masks. Specify theDataFormMaskedItem.Mask
property to define a mask.<dxdf:DataFormMaskedItem Mask="+1 (000) 000-0000" />
-
Specify a
DataFormItem
'sKeyboard
property to define a type of keyboard used to input text.