I have to create some dynamic data fields inside RadDataForm so I've added an ItemsControl inside my RadDataForm. Please see code below for example. Everything works fine. A custom DataTemplateSelector checks a property called Value. If Value is of type string ItemsControl is using DataFormDataField template to display it with a TextBox. If Value is of type datetime ItemsControl is using DataFormDateField template to display it with a RadDatePicker. That's great but I'm having trouble with validation. I use Item level attribute-based validation as described in your documentation. This works perfect on usual data fields like the two shown below (ID and Name). But validation is not executed on my bound properties inside those mentioned DataTemplates. Inside every DataTemplate there is a DataBinding to property Value of my ViewModel. Just like ID and Name, Value also has Item level attribute-based validation ([Required(AllowEmptyStrings = false)]). When ID or Name are empty validation comes into place and I can not commit RadDataForm until I enter some text. That's what I want for my Value property, too. I hope this is understandable.
Can you help me on this? I don't know what I am doing wrong here. It seems my validation rules/data annotations are just not recognized by RadDataForm when the binding is inside a DataTemplate.
<!-- ID -->
<
t:DataFormDataField
Label
=
"ID"
Description
=
"Todo"
DataMemberBinding
=
"{Binding ID, Mode=OneWay}"
>
<
t:DataFormDataField.Content
>
<
t:RadWatermarkTextBox
Text
=
"{Binding ID, Mode=OneWay}"
IsReadOnly
=
"True"
/>
</
t:DataFormDataField.Content
>
</
t:DataFormDataField
>
<!-- Name -->
<
t:DataFormDataField
Label
=
"Name"
Description
=
"Todo"
DataMemberBinding
=
"{Binding Name, Mode=TwoWay, NotifyOnValidationError=True}"
>
<
t:DataFormDataField.Content
>
<
t:RadWatermarkTextBox
Text
=
"{Binding Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
WatermarkContent
=
"Please fill in your name"
/>
</
t:DataFormDataField.Content
>
</
t:DataFormDataField
>
<!-- DYNAMIC DATA FIELDS -->
<
ItemsControl
ItemsSource
=
"{Binding Source={StaticResource CollectionViewSource}}"
Focusable
=
"False"
>
<
ItemsControl.ItemTemplateSelector
>
<
v:MyDataTemplateSelector
>
<!-- Text DataTemplate (Value is string so show it in DataFormDataField) -->
<
v:MyDataTemplateSelector.TextBoxDataTemplate
>
<
DataTemplate
>
<
t:DataFormDataField
Label
=
"{Binding Label, Mode=OneWay}"
Description
=
"{Binding ToolTip, Mode=OneWay}"
DataMemberBinding
=
"{Binding Value, Mode=TwoWay, NotifyOnValidationError=True}"
>
<
t:DataFormDataField.Content
>
<
t:RadWatermarkTextBox
Text
=
"{Binding Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
WatermarkContent
=
"Please insert value"
/>
</
t:DataFormDataField.Content
>
</
t:DataFormDataField
>
</
DataTemplate
>
</
v:MyDataTemplateSelector.TextBoxDataTemplate
>
<!-- Date DataTemplate (Value is datetime so show it as DataFormDateField) -->
<
v:MyDataTemplateSelector.DateDataTemplate
>
<
DataTemplate
>
<
t:DataFormDateField
Label
=
"{Binding Label, Mode=OneWay}"
Description
=
"{Binding ToolTip, Mode=OneWay}"
DataMemberBinding
=
"{Binding Value, Mode=TwoWay, NotifyOnValidationError=True}"
>
<
t:DataFormDateField.Content
>
<
t:RadDatePicker
DateSelectionMode
=
"Year"
SelectedValue
=
"{Binding Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
/>
</
t:DataFormDateField.Content
>
</
t:DataFormDateField
>
</
DataTemplate
>
</
v:MyDataTemplateSelector.DateDataTemplate
>
<!-- More DataTemplates here ... -->
</
v:MyDataTemplateSelector
>
</
ItemsControl.ItemTemplateSelector
>
</
ItemsControl
>
Can you help me on this? I don't know what I am doing wrong here. It seems my validation rules/data annotations are just not recognized by RadDataForm when the binding is inside a DataTemplate.