ItemTemplateSelector
When binding your RadTreeView to a collection, you are able to configure the visualization of the data and the appearance of the RadTreeViewItems via the ItemTemplate and the ItemTemplateSelectior properties.
If you want to read about the ItemTemplate, see the main topic ItemTemplate.
The purpose of this tutorial is to show you how to create and apply an ItemTemplateSelector.
ItemTemplateSelector Property
The most common use of the "selectors" is to display different kind of data (different kind of items).
To create your own selector you have to use Visual Studio.
-
Create a class and name it LeagueDataTemplateSelector. The LeagueDataTemplateSelector must inherit from the DataTemplateSelector class.
-
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.
Please note that in order to use the HierarchicalDataTemplate class, you need to add a using for the System.Windows namespace.
-
Define the created selector as a resource in your XAML and set it to the ItemTemplateSelector property.
The data source class RadTreeViewSampleData assigned to the RadTreeView is covered in greater details in the chapter Binding to Object.
And the result of the demo can be seen on the next figure: