# Getting Started with WPF TreeView

This tutorial will walk you through the creation of a sample application that contains **RadTreeView**.

* [Adding Telerik Assemblies Using NuGet](https://www.telerik.com/products/wpf/documentation/controls/radtreeview/getting-started/getting-started#adding-telerik-assemblies-using-nuget)
* [Adding Assembly References Manually](https://www.telerik.com/products/wpf/documentation/controls/radtreeview/getting-started/getting-started#adding-assembly-references-manually)
* [Defining a RadTreeView](https://www.telerik.com/products/wpf/documentation/controls/radtreeview/getting-started/getting-started#defining-a-radtreeview)
* [Adding Items to RadTreeView](https://www.telerik.com/products/wpf/documentation/controls/radtreeview/getting-started/getting-started#adding-items-to-radtreeview)
* [Data Binding RadTreeView](https://www.telerik.com/products/wpf/documentation/controls/radtreeview/getting-started/getting-started#data-binding-radtreeview)
* [Enable Drag and Drop](https://www.telerik.com/products/wpf/documentation/controls/radtreeview/getting-started/getting-started#enable-drag-and-drop)
* [Setting a Theme](https://www.telerik.com/products/wpf/documentation/controls/radtreeview/getting-started/getting-started#setting-a-theme)

## Adding Telerik Assemblies Using NuGet

To use **RadTreeView** when working with NuGet packages, install the `Telerik.Windows.Controls.Navigation.for.Wpf.Xaml` package. The [package name may vary](https://www.telerik.com/products/wpf/documentation/installation/manual-setup-guides/nuget/available-packages) slightly based on the Telerik dlls set - [Xaml or NoXaml](https://www.telerik.com/products/wpf/documentation/styling-and-appearance/xaml-vs-noxaml)

Read more about NuGet installation in the [Installing UI for WPF from NuGet Package](https://www.telerik.com/products/wpf/documentation/installation/manual-setup-guides/nuget/nuget-installation) article.

> tip With the 2025 Q1 release, the Telerik UI for WPF has a new licensing mechanism. You can learn more about it [here](https://www.telerik.com/products/wpf/documentation/installation/licensing/installing-license-key).

## Adding Assembly References Manually

If you are not using NuGet packages, you can add a reference to the following assemblies:

* **Telerik.Licensing.Runtime**
* **Telerik.Windows.Controls**
* **Telerik.Windows.Controls.Navigation**
* **Telerik.Windows.Data**

You can find the required assemblies for each control from the UI for WPF suite in the [Controls Dependencies](https://www.telerik.com/products/wpf/documentation/common-information/installation-installing-dependencies-wpf) help article.

## Defining a RadTreeView

You can add **RadTreeView** manually in XAML as demonstrated in **Example 1**.

**Example 1: Adding RadTreeView in XAML**

```XAML
<telerik:RadTreeView />
```

**RadTreeView** doesn't display any content when it is not populated with items, so at this point there should be nothing displayed on the screen.

## Adding Items to RadTreeView

**RadTreeView** works with **RadTreeViewItem** elements, which should be added in the **Items** collection of the control.

**Example 2: Adding RadTreeViewItems in XAML**

```XAML
<telerik:RadTreeView>
    <telerik:RadTreeView.Items>
        <telerik:RadTreeViewItem Header="Football" />
        <telerik:RadTreeViewItem Header="Tennis" />
        <telerik:RadTreeViewItem Header="Cycling" />
        <telerik:RadTreeViewItem Header="Basketball" />
    </telerik:RadTreeView.Items>
</telerik:RadTreeView>
```

**Example 3: Adding RadTreeViewItems in code**

```C#
RadTreeView treeView = new RadTreeView();
treeView.Items.Add(new RadTreeViewItem() { Header = "Football" });
treeView.Items.Add(new RadTreeViewItem() { Header = "Tennis" });
treeView.Items.Add(new RadTreeViewItem() { Header = "Cycling" });
treeView.Items.Add(new RadTreeViewItem() { Header = "Basketball" });
```

```VB.NET
	Dim treeView As New RadTreeView()
	treeView.Items.Add(New RadTreeViewItem() With { _
		.Header = "Football" _
	})
	treeView.Items.Add(New RadTreeViewItem() With { _
		.Header = "Tennis" _
	})
	treeView.Items.Add(New RadTreeViewItem() With { _
		.Header = "Cycling" _
	})
	treeView.Items.Add(New RadTreeViewItem() With { _
		.Header = "Basketball" _
	})
```

> caption RadTreeView flat data example

![WPF RadTreeView RadTreeView flat data example](https://www.telerik.com/products/wpf/documentation/assets/4d88569ae4183e8fa117a144d5f9398a/radtreeview-getting-started-01.png)

> The **Items** property of the treeview component is also its content property, so adding the children through the Items collection is not necessary in XAML. You can do it without wrapping the items into the RadTreeView\.Items tag. The same applies for the **Items** property of RadTreeViewItem.

**RadTreeViewItem** is hierarchical items control, which means that it can contain children containers that hold children on their own. In other words, you can nest items into another item.

> The **RadTreeViewItem** class expose a **Header** property that is used to define the content of its header.

**Example 4: Nesting RadTreeViewItems**

```XAML
<telerik:RadTreeView>
    <telerik:RadTreeViewItem Header="Sport Categories" IsExpanded="True">
        <telerik:RadTreeViewItem Header="Football" IsExpanded="True">
            <telerik:RadTreeViewItem Header="Futsal"/>
            <telerik:RadTreeViewItem Header="Soccer"/>
        </telerik:RadTreeViewItem>
        <telerik:RadTreeViewItem Header="Tennis"/>
        <telerik:RadTreeViewItem Header="Cycling"/>
    </telerik:RadTreeViewItem>
</telerik:RadTreeView>
```

> caption RadTreeView nested items example

![WPF RadTreeView RadTreeView nested items example](https://www.telerik.com/products/wpf/documentation/assets/12924cba3fc72c8cd06c62b9e5199a76/radtreeview-getting-started-02.png)

## Data Binding RadTreeView

The **RadTreeView** control allows you to data bind it to a collection of business objects and define their visual appearance. You can read more on how to bind **RadTreeView** in the [Binding to Object](https://www.telerik.com/products/wpf/documentation/controls/radtreeview/populating-with-data/data-binding-to-object) help article. You can also take a look at the other articles from the [Populating with Data](https://www.telerik.com/products/wpf/documentation/controls/radtreeview/populating-with-data/overview) section of the help where you can find information about binding to an XML file and different services. There you can also find information about **HierarchicalDataTemplate**, which is used to define the look and feel of the **RadTreeViewItems** in a data binding scenario.

## Enable Drag and Drop

**RadTreeView** supports drag and drop functionality. To enable this feature, you only need to set the **IsDragDropEnabled** property to **True**.

**Example 5: IsDragDropEnabled setting**

```XAML
<telerik:RadTreeView IsDragDropEnabled="True"/>
```

**Example 6** demonstrates a runnable code snippet using **RadTreeView** with its drag and drop enabled.

**Example 6: Drag and drop set up**

```XAML
<telerik:RadTreeView IsDragDropEnabled="True">
    <telerik:RadTreeViewItem Header="Sport Categories" IsExpanded="True">
        <telerik:RadTreeViewItem Header="Football" IsExpanded="True">
            <telerik:RadTreeViewItem Header="Futsal"/>
            <telerik:RadTreeViewItem Header="Soccer"/>
        </telerik:RadTreeViewItem>
        <telerik:RadTreeViewItem Header="Tennis"/>
        <telerik:RadTreeViewItem Header="Cycling"/>
    </telerik:RadTreeViewItem>
</telerik:RadTreeView>
```

> caption Drag and drop visual example

![WPF RadTreeView Drag and drop visual example](https://www.telerik.com/products/wpf/documentation/assets/9c14f6ac788aa1c5613fc6c6a2ad3ee9/radtreeview-getting-started-03.png)

> tip You can find out more about the drag and drop support in the [Drag and Drop](https://www.telerik.com/products/wpf/documentation/controls/radtreeview/features/dragdrop/drag-and-drop) help article.

## Setting a Theme

The controls from our suite support different themes. You can see how to apply a theme different than the default one in the [Setting a Theme (Using Implicit Styles)](https://www.telerik.com/products/wpf/documentation/styling-and-appearance/styling-apperance-setting-a-theme-overview) help article.

> important Changing the theme using implicit styles will affect all controls that have styles defined in the merged resource dictionaries. This is applicable only for the controls in the scope in which the resources are merged.

To change the theme, you can follow the steps below:

* Choose between the themes and add reference to the corresponding theme assembly (ex: Telerik.Windows.Themes.Windows8.dll). You see the different themes applied in the Theming examples from our demos application.

* Merge the ResourceDictionaries with the namespace required for the controls that you are using from the theme assembly. For **RadTreeView**, you will need to merge the following resources:

  * **Telerik.Windows.Controls.xaml**
  * **Telerik.Windows.Controls.Navigation.xaml**

  **Example 8** demonstrates where you can merge the ResourceDictionaries so they are applied globally for the entire application.

  **Example 8: Merge the ResourceDictionaries**

  ```XAML
  <Application.Resources>
      <ResourceDictionary>
          <ResourceDictionary.MergedDictionaries>
              <ResourceDictionary Source="/Telerik.Windows.Themes.Windows8;component/Themes/Telerik.Windows.Controls.xaml" />
              <ResourceDictionary Source="/Telerik.Windows.Themes.Windows8;component/Themes/Telerik.Windows.Controls.Navigation.xaml" />
          </ResourceDictionary.MergedDictionaries>
      </ResourceDictionary>
  </Application.Resources>
  ```

**Figure 4** shows **RadTreeView** with Windows8 theme applied.

> caption RadTreeView with Windows8 theme

![WPF RadTreeView RadTreeView with Windows8 theme](https://www.telerik.com/products/wpf/documentation/assets/64209d88297f66643a468ac46c513978/radtreeview-getting-started-04.png)

## Telerik UI for WPF Learning Resources

* [Telerik UI for WPF TreeView Component](https://www.telerik.com/products/wpf/treeview.aspx)
* [Getting Started with Telerik UI for WPF Components](https://www.telerik.com/products/wpf/documentation/getting-started/first-steps-nuget)
* [Telerik UI for WPF Installation](https://www.telerik.com/products/wpf/documentation/installation/manual-setup-guides/installation-guide)
* [Telerik UI for WPF and WinForms Integration](https://www.telerik.com/products/wpf/documentation/common-information/winforms-integration/overview)
* [Telerik UI for WPF Visual Studio Templates](https://www.telerik.com/products/wpf/documentation/installation/manual-setup-guides/visual-studio-templates)
* [Setting a Theme with Telerik UI for WPF](https://www.telerik.com/products/wpf/documentation/styling-and-appearance/styling-apperance-setting-a-theme-overview)
* [Telerik UI for WPF Virtual Classroom (Training Courses for Registered Users)](https://learn.telerik.com/learn/course/external/view/elearning/16/telerik-ui-for-wpf)
* [Telerik UI for WPF License Agreement](https://www.telerik.com/purchase/license-agreement/wpf-dlw-s)

## See Also

* [Overview](https://www.telerik.com/products/wpf/documentation/controls/radtreeview/overview2)
* [Visual Structure](https://www.telerik.com/products/wpf/documentation/controls/radtreeview/visual-structure)
* [Expanding and Collapsing Items](https://www.telerik.com/products/wpf/documentation/controls/radtreeview/features/treeview-item/feautres-treeviewitem-expanding-and-collapsing-items)
* [Selection](https://www.telerik.com/products/wpf/documentation/controls/radtreeview/features/feautres-treeviewitem-selection)
* [Setting a Theme (Using Implicit Styles)](https://www.telerik.com/products/wpf/documentation/styling-and-appearance/styling-apperance-setting-a-theme-overview)
* [Populating with Data - Overview](https://www.telerik.com/products/wpf/documentation/controls/radtreeview/populating-with-data/overview)
* [Editing Control Templates](https://www.telerik.com/products/wpf/documentation/styling-and-appearance/styling-apperance-editing-control-templates)
* [Events - Overview](https://www.telerik.com/products/wpf/documentation/controls/radtreeview/events/overview)
