Telerik UI for Windows Phone by Progress

RadDataForm is easily setup by adding the control to a Windows Phone Page and binding its CurrentItem property to an object which properties are to be visualized in the Data Form.

Getting started with RadDataForm

Create a Windows Phone application and, after adding the Telerik.Windows.Controls.Input namespace in the XAML file of the page, put a RadDataForm instance in the main layout element of the page:

CopyXAML
<Grid x:Name="LayoutRoot" Background="Transparent">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <!--TitlePanel contains the name of the application and page title-->
    <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
        <TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
        <TextBlock x:Name="PageTitle" Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
    </StackPanel>

    <!--ContentPanel - place additional content here-->
    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
          <telerikInput:RadDataForm
              EditorCreationMode="CreateByDefault"
              x:Name="radDataForm"/>
    </Grid>
</Grid>

Then define a class in the code behind file which looks like the following:

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;

    public string SecondName
    {
        get
        {
            return secondName;
        }
        set
        {
            secondName = value;
        }
    }

    public UserGender Gender
    {
        get
        {
            return gender;
        }
        set
        {
            gender = value;
        }
    }

    public DateTime DateOfBirth
    {
        get
        {
            return dateOfBirth;
        }
        set
        {
            dateOfBirth = value;
        }
    }

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

    public bool ReceivesNewsLetter
    {
        get
        {
            return receivesNewsLetter;
        }
        set
        {
            receivesNewsLetter = value;
        }
    }

    public string FirstName
    {
        get
        {
            return this.firstName;
        }
        set
        {
            this.firstName = value;
        }
    }
}

An instance of this class will be used as CurrentItem of RadDataForm.

Now that we have a class definition and a RadDataForm instance on our page, go to the constructor of the page and add the following code:

CopyC#
public partial class MainPage : PhoneApplicationPage
{
    // Constructor
    public MainPage()
    {
        InitializeComponent();
        User user = new User();
        this.radDataForm.CurrentItem = user;
    }
}

Setting the CurrentItem property will make RadDataForm analyze the source object, retrieve its public properties and map each one of them to a corresponding editor field according to the type of the property:

Data Form Getting Started 1

These are the basic steps you need to take in order to have RadDataForm functioning in your Windows Phone application.

Note
The EditorCreationMode property is set to CreateByDefault because we want to have RadDataForm automatically consider all public properties on the business object and create editors for them.

Note
By default all editors are labeled with the name of the property on the business object. You can find useful information on how to define custom labels in the Defining Labels and Field Order chapter.

The EditorCreationMode property

The EditorCreationMode property is used to define how RadDataForm creates editors for the public properties of the business object assigned as CurrentItem. Two options are available:

  • CreateByDefault
  • IgnoreByDefault

The CreateByDefault option implies that editors for each public property will be created unless the property is marged with the IgnoreAttribute.

The IgnoreByDefault option implies that editors for each public property are created as long as the property is marked with the FormFieldAttribute.

The EditorCreationMode property is used only when RadDataForm has no XAML definition of its layout. When the layout of the fields is defined in XAML the presence or absence of DataField elements for the corresponding properties defines whether editors will be or will no be created for the properties.

See Also