ItemEditTemplateSelector
Telerik RadTreeView also supports ItemEditTemplateSelector. This tutorial will walk you through the common task of creating and applying ItemEditTemplateSelector.
If you want to read about ItemEditTemplate, see the main topic ItemEditTemplate.
ItemEditTemplateSelector
The most common use of the "selectors" is to display different kind of data (different kind of items).
For the purpose of this tutorial will be used the following treeview declaration:
If you want to read more about HierarchicalDataTemplate and DataBinding, see the main topics about HierarchicalDataTemplate and Binding to Object.
-
Create three DataTemplates in the resources of your application. These templates will be used by the selector as edit templates.
-
LeagueItemEditTemplate
-
DivisionItemEditTemplate
-
TeamItemEditTemplate
In order to use the Telerik RadMaskedNumericInput you need to add a reference to the Telerik.Windows.Controls.Input assembly in your user control.
These are the three DataTemplates, which will be used as edit templates. Accordingly, when the object type is League, then the LeagueItemEditTemplate will be applied; when the object type is Division, then the DivisionItemEditTemplate will be applied; when the object type is Team, then the TeamItemEditTemplate will be applied.
-
The next step is to create a selector where the logic about selecting the right template will be.
-
Create a new class, named LeagueItemEditTemplateSelector, which derives from DataTemplateSelector.
-
Override the SelectTemplate method and implement your custom logic in it. The method accepts as arguments an object and a DependencyObject. The object argument is the actual object being bound and the DependecyObject is the container for it.
-
Define the created selector as a resource in your XAML and set it to the ItemEditTemplateSelector property.
The Telerik RadTreeView provides a default ItemEditTemplate which takes precedence. That's why in order to use ItemEditTemplateSelector, you need to null the ItemEditTemplate. In code this is trivial, in XAML can be done with the following:
ItemEditTemplate="{x:Null}"
Don't forget to null the ItemEditTemplate, because otherwise your template selector won't be applied.
Here are some snapshots when you edit an object of type League and when you edit an object of type Team: