New to Telerik UI for WPFStart a free 30-day trial

Defining Custom DataFields

Updated on Sep 24, 2025

This help article illustrates how to define your own DataField type.

For this purpose you need to create a class which inherits from DataFormDataField and overrides its GetControl() and GetControlBindingProperty() methods:

Example 1: Creating the DataFormNumericUpDownField class

C#
	public class DataFormNumericUpDownField : DataFormDataField
	{
	    protected override DependencyProperty GetControlBindingProperty()
	    {
	        return RadNumericUpDown.ValueProperty;
	    }
	    protected override Control GetControl()
	    {
	        DependencyProperty dependencyProperty = this.GetControlBindingProperty();
	        RadNumericUpDown numericUpDown = new RadNumericUpDown();
	        if (this.DataMemberBinding != null)
	        {
	            var binding = this.DataMemberBinding;
	            numericUpDown.SetBinding(dependencyProperty, binding);
	        }
	        numericUpDown.SetBinding(RadNumericUpDown.IsEnabledProperty, new Binding("IsReadOnly") { Source = this, Converter = new InvertedBooleanConverter() });
	        return numericUpDown;
	    }
	}

The next step is to handle RadDataForm's AutoGeneratingField event and set the DataField to the new DataFormNumericUpDownField:

Example 2: Initializing a RadDataForm

XAML
	<telerik:RadDataForm x:Name="DataForm1" AutoGeneratingField="RadDataForm_AutoGeneratingField" />

Example 3: Handling the AutoGeneratingField event

C#
	private void RadDataForm_AutoGeneratingField(object sender, Telerik.Windows.Controls.Data.DataForm.AutoGeneratingFieldEventArgs e)
	{
	    if (e.DataField.Label.Equals("Number"))
	    {
	        e.DataField = new DataFormNumericUpDownField() { Label = e.DataField.Label, DataMemberBinding = e.DataField.DataMemberBinding };
	    }
	}

And here's how you can use the DataFormNumericUpDownField in XAML:

Example 4: Using the DataFormNumericUpDownField in a Custom DataTemplate

XAML
	<Grid>
	    <Grid.Resources>
	        <DataTemplate x:Key="MyTemplate">
	            <StackPanel>
	                <telerik:DataFormDataField  Label="First Name" DataMemberBinding="{Binding FirstName, Mode=TwoWay}" />
	                <telerik:DataFormDataField  Label="Last Name" DataMemberBinding="{Binding LastName, Mode=TwoWay}" />
	                <my:DataFormNumericUpDownField Label="Age" DataMemberBinding="{Binding Age, Mode=TwoWay}" />
	            </StackPanel>
	        </DataTemplate>
	    </Grid.Resources>
	    <telerik:RadDataForm AutoGenerateFields="False"
	                     ReadOnlyTemplate="{StaticResource MyTemplate}"
	                     EditTemplate="{StaticResource MyTemplate}"
	                     NewItemTemplate="{StaticResource MyTemplate}">
	    </telerik:RadDataForm>
	</Grid>

See Also

In this article
See Also
Not finding the help you need?
Contact Support