Telerik UI for Windows Phone by Progress

RadDataForm exposes a convenient API that allows you to customize the way fields are populated. By default, the editor fields are put into a Grid panel and positioned in rows or columns according to the values of the Grid.Row and Grid.Column attached properties set on each field.

Defining the Order of the Editor Fields

After binding a RadDataForm to a data object the editor fields will be populated in a default order as they appear in the data object which might not always be the desired behavior. You can change this by simply reordering the properties in your business entity accordingly. If that is not possible, you can use the DataFieldCreated event and set the Grid.Row attached property to the DataFormField instance with a value that describes the order you want assigned to the field as shown in the code snippet below:

CopyC#
private void radDataForm_DataFieldCreated_1(object sender, Telerik.Windows.Controls.DataFieldCreatedEventArgs e)
{
    switch(e.AssociatedField.PropertyKey)
    {
        case "DateOfBirth":
            Grid.SetRow(e.AssociatedField.AssociatedDataField, 0);
            break;
        case "Gender":
            Grid.SetRow(e.AssociatedField.AssociatedDataField, 1);
            break;
        case "ReceivesNewsletter":
            Grid.SetRow(e.AssociatedField.AssociatedDataField, 2);
            break;
        case "Password":
            Grid.SetRow(e.AssociatedField.AssociatedDataField, 3);
            break;
        case "FirstName":
            Grid.SetRow(e.AssociatedField.AssociatedDataField, 4);
            break;
        case "SecondName":
            Grid.SetRow(e.AssociatedField.AssociatedDataField, 5);
            break;
    }
}

Defining Custom Labels for the Editor Fields

By default all editor fields are labeled by taking the name of the corresponding property on the source object. In most of the real-life scenarios you will need to change the labels with more friendly ones or event localize them. You can define custom labels by using the FieldInfo attribute as shown in the code snippet below:

CopyC#
public class User
{
    public enum UserGender
    {
        Female,
        Male
    }

    private string firstName;
    private string secondName;
    private UserGender gender;
    private DateTime dateOfBirth;
    private string password;
    private bool receivesNewsLetter;

    [FieldInfo(FieldHeader="First name")]
    public string FirstName
    {
        get
        {
            return this.firstName;
        }
        set
        {
            this.firstName = value;
        }
    }

    [FieldInfo(FieldHeader = "Second name")]
    public string SecondName
    {
        get
        {
            return secondName;
        }
        set
        {
            secondName = value;
        }
    }

    public string Password
    {
        get
        {
            return password;
        }
        set
        {
            password = value;
        }
    }

    [FieldInfo(FieldHeader = "Subscribe for newsletter")]
    public bool ReceivesNewsLetter
    {
        get
        {
            return receivesNewsLetter;
        }
        set
        {
            receivesNewsLetter = value;
        }
    }

    [FieldInfo(FieldHeader = "Date of birth")]
    public DateTime DateOfBirth
    {
        get
        {
            return dateOfBirth;
        }
        set
        {
            dateOfBirth = value;
        }
    }

    [FieldInfo(FieldHeader = "Gender")]
    public UserGender Gender
    {
        get
        {
            return gender;
        }
        set
        {
            gender = value;
        }
    }
}

Labels and XAML

If you need to localize your labels you can define them in XAML. This is explained in the DataForm and XAMLs ection.

See Also