Getting Start with RadTreeMap

This tutorial will walk you through the creation of a sample application that contains RadTreeMap control.

Assembly References

In order to use RadTreeMap, you will need to add references to the following assemblies:

  • Telerik.Windows.Controls
  • Telerik.Windows.Controls.DataVisualization
  • Telerik.Windows.Data

You can find the required assemblies for each control from the suite in the Controls Dependencies help article.

Setting up the Data Source

To populate the control with tiles you will need to provide a collection of items that will be assigned to its ItemsSource property.

For this example we will use a simple hierarchical structure consisting of teams, managers and employees.

Example 1: Defining the models

 public class Team 
{ 
    public string Name { get; set; } 
    public ObservableCollection<Manager> Managers { get; set; } 
    public int ManagersCount 
    { 
        get { return this.Managers.Count; } 
    } 
} 
 
public class Manager 
{ 
    public string Name { get; set; } 
    public ObservableCollection<Employee> Employees { get; set; } 
    public int EmployeesCount 
    { 
        get { return this.Employees.Count; } 
    } 
} 
 
public class Employee 
{ 
    public string Name { get; set; } 
    public double Salary { get; set; } 
} 

Example 2: Populating a collection with the data

public ObservableCollection<Team> GetData() 
{ 
    Random r = new Random();             
    var teams = new ObservableCollection<Team>();             
    for (int i = 0; i < 3; i++) 
    { 
        var team = new Team() { Name = "Team " + i, Managers = new ObservableCollection<Manager>() };                
        for (int k = 0; k < 2; k++) 
        { 
            var manager = new Manager() { Name = "Manager " + k, Employees = new ObservableCollection<Employee>() }; 
            int employeesCount = r.Next(3, 6); 
            for (int y = 0; y < 3; y++) 
            { 
                manager.Employees.Add(new Employee() { Name = "Employee " + y, Salary = r.Next(3000, 10000) }); 
            }                     
            team.Managers.Add(manager); 
        } 
        teams.Add(team); 
    } 
 
    return team; 
} 

Setting up the RadTreeMap

To set up the control you can set two essential properties - ItemsSource and TypeDefinitions. The TypeDefinitions is a collection of TypeDefinition objects which contain information that tells the tree map how to fetch the data from the objects in the ItemsSource.

The ValuePath determines the size of the tile.

The LabelPath determines the label that will be displayed over the tile.

The TargetTypeName contains the class name of the corresponding object in the ItemsSource.

The ChildrenPath is the path to the property that holds the children's collection.

Example 3: Defining RadTreeMap

<telerik:RadTreeMap x:Name="radTreeMap"> 
    <telerik:RadTreeMap.TypeDefinitions> 
        <telerik:TypeDefinition TargetTypeName="Team" ValuePath="ManagersCount" ChildrenPath="Managers" LabelPath="Name" /> 
        <telerik:TypeDefinition TargetTypeName="Manager" ValuePath="EmployeesCount" ChildrenPath="Employees" LabelPath="Name" /> 
        <telerik:TypeDefinition TargetTypeName="Employee" ValuePath="Salary" LabelPath="Name"> 
            <telerik:TypeDefinition.Mappings> 
                <telerik:ValueGradientColorizer RangeMinimum="3000" RangeMaximum="10000"> 
                    <GradientStop Offset="0" Color="Red" /> 
                    <GradientStop Offset="0.50" Color="Yellow" /> 
                    <GradientStop Offset="1" Color="Green" /> 
                </telerik:ValueGradientColorizer> 
            </telerik:TypeDefinition.Mappings> 
        </telerik:TypeDefinition>                
    </telerik:RadTreeMap.TypeDefinitions> 
</telerik:RadTreeMap> 

Example 4: Setting the ItemsSource in XAML

<telerik:RadTreeMap ItemsSource="{Binding MyDataSourceProperty}" /> 

Example 5: Setting the ItemsSource in code (see Example 2)

this.radTreeMap.ItemsSource = GetData(); 

Figure 1: RadTreeMap

See Also

In this article
Not finding the help you need? Improve this article