# Customized Fields

RadDataForm auto-generates its fields by default based on the properties of the source objects. They are stacked vertically in a standard form layout and depend on the type of each property.

> caption RadDataForm with autogenerated fields

![RadDataForm with autogenerated fields](https://www.telerik.com/products/wpf/documentation/assets/cd73e6bfff43bb80155ff759dedc9c4a/raddataform_bindtocollection.png)

However, sometimes you may decide on customizing or totally changing them. In addition to displaying auto-generated fields, RadDataForm allows custom placement of the fields. Consequently, it may be designed to look like:

> caption RadDataForm with customized fields

![RadDataForm with customized fields](https://www.telerik.com/products/wpf/documentation/assets/701067b4114ea31f39065085d53ccd94/raddataform_customizedfields.png)

The key properties here are:

* **ReadOnlyTemplate**

* **NewItemTemplate**

* **EditTemplate**

All of them are of type **DataTemplate** and there is no limitation on the types of controls you may place inside. Their **DataContext** will be the **current item** of the RadDataForm.

> Custom-defined fields may coexist with the auto-generated ones or the auto-generated may be canceled.

Once you set the **AutoGenerateFields** property of the RadDataForm to **False**, the implicit generation of the fields will be turned off:

**Example 1: Disabling the autogeneration of fields**

```C#
this.DataForm1.AutoGenerateFields = false;
```

```VB.NET
Me.DataForm1.AutoGenerateFields = False
```

**Example 1: Disabling the autogeneration of fields**

```XAML
<telerik:RadDataForm x:Name="DataForm1" AutoGenerateFields="False" />
```

The three data templates - ReadOnlyTemplate, NewItemTemplate and EditTemplate - correspond to the relevant modes of RadDataForm. So, when the form is in read-only mode, the ReadOnlyTemplate is displayed, when in edit-mode - the EditTemplate and when a new item is added - the NewItemTemplate.

Lets say you have defined the following DataTemplate:

**Example 2: Definition of a DataTemplate**

```XAML
<Grid>
    <Grid.Resources>
        <DataTemplate x:Key="MyTemplate">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition/>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <telerik:DataFormDataField Label="First Name" DataMemberBinding="{Binding FirstName, Mode=TwoWay}" />
                <telerik:DataFormDataField Grid.Column="1" Label="Last Name" DataMemberBinding="{Binding LastName, Mode=TwoWay}" />
                <telerik:DataFormCheckBoxField Grid.Column="1" Grid.Row="1" Label="Married" DataMemberBinding="{Binding IsMarried, Mode=TwoWay}" />
            </Grid>
        </DataTemplate>
    </Grid.Resources>
</Grid>
```

Then you can assign the ReadOnlyTemplate like so:

**Example 3: Assigning a ReadOnlyTemplate**

```XAML
<telerik:RadDataForm AutoGenerateFields="False" 
                ReadOnlyTemplate="{StaticResource MyTemplate}">
</telerik:RadDataForm>
```

**Figure 3** shows the result:

> caption RadDataForm with custom ReadOnlyTemplate

![RadDataForm with custom ReadOnlyTemplate](https://www.telerik.com/products/wpf/documentation/assets/701067b4114ea31f39065085d53ccd94/raddataform_customizedfields.png)

Similarly you can assign the EditTemplate:

**Example 3: Assigning an EditTemplate**

```XAML
<telerik:RadDataForm AutoGenerateFields="False" 
                ReadOnlyTemplate="{StaticResource MyTemplate}">
</telerik:RadDataForm>
```

The result can bee seen in **Figure 4**:

> caption RadDataForm with custom EditTemplate

![RadDataForm with custom EditTemplate](https://www.telerik.com/products/wpf/documentation/assets/5d0e8be13a21a54088cb6411cf495a95/raddataform_autogeneratedfiels_editmode.png)

For each different state, you will need to define another template. It could be with the same content or it could be with a different one.

> You will need to define separate templates for the read-only and edit modes.

On the other hand, if you make your mind on displaying quite different controls instead of the standard ones, you may place them in the data templates as well. For example, for editing number values, you may use the RadNumericUpDown control:

**Example 4: Using a RadNumericUpDown for editing number values**

```XAML
<Grid>
    <Grid.Resources>
        <DataTemplate x:Key="MyTemplate">
            <StackPanel Orientation="Horizontal" >
                <TextBlock Text="Age" Width="20" Height="20" Foreground="Blue" Margin="0,0,10,0" />
                <telerik:RadNumericUpDown Value="{Binding Age, Mode=TwoWay}" />
            </StackPanel>
        </DataTemplate>
    </Grid.Resources>
    <telerik:RadDataForm AutoGenerateFields="False" 
                    EditTemplate="{StaticResource MyTemplate}">
    </telerik:RadDataForm>
</Grid>
```

The result is displayed in **Figure 5**:

> caption RadNumericUpDown as EditTemplate

![RadNumericUpDown as EditTemplate](https://www.telerik.com/products/wpf/documentation/assets/c95425d3cb91a17187ffa03d4cc6698a/raddataform_customizedfields_newcontrols.png)

Furthermore, you may customize the data fields as well. For example, a regular **DataFormDataField** may be defined in a custom template and the default content may be replaced:

**Example 5: Replacing the default field content**

```XAML
<Grid x:Name="LayoutRoot" Background="White">
    <Grid.Resources>
        <DataTemplate x:Key="MyTemplate">
            <StackPanel Orientation="Horizontal" >
                <telerik:DataFormDataField>
                    <StackPanel Orientation="Horizontal">
                        <TextBox Text="{Binding Age, Mode=TwoWay}" Margin="0,0,10,0" />
                        <TextBlock Text="years" Foreground="Green"  VerticalAlignment="Bottom" />
                    </StackPanel>
                </telerik:DataFormDataField>
            </StackPanel>
        </DataTemplate>
    </Grid.Resources>
    <telerik:RadDataForm AutoGenerateFields="False" 
                   EditTemplate="{StaticResource MyTemplate}">
    </telerik:RadDataForm>
</Grid>
```

> caption Replacing the default field content

![Replacing the default field content](https://www.telerik.com/products/wpf/documentation/assets/e19b48cfeb569892aa5cae5f4103ec50/raddataform_customizedfields_newcontent.png)
