DataTemplate Selectors
This article shows how to conditionally load different ReadOnly/Edit DataTemplates, according to RadDataForm’s CurrentItem. For some additional information on DataTemplateSelectors, please refer to General FAQ documentation article.
DataTemplate selectors affect both RadDataForm’s auto-generated fields and manually defined ones.
For this tutorial we will extend our example from the Getting Started documentation article by defining custom edit templates in XAML (Example 1).
Example 1: Defining Custom DataTemplateSelector Templates in the EditTemplateSelector
Here we define a DataTemplateSelector(Example 2):
Example 2: Defining a DataTemplateSelector
As a result when RadDataForm is in edit mode the background color of the Salary DataFormDataField will change to red (Figure 1), when the employee's salary is greater than 2500 or blue when it is less.
Figure 1: Result of DataTemplateSelector
An analogical approach should be used to set a ReadOnlyTemplateSelector.
Find a runnable project of the previous example in the WPF Samples GitHub repository.