# Data Binding

## DataContext

The purpose of the **DataContext** is to hold the data that will be bound (like a data source). If the **DataContext** is empty no binding will be applied. The **DataContext** can be set from both XAML and managed code:

```XAML
<telerik:RadTabControl x:Name="radTabControl" DataContext="{Binding MyTabItems}" />
```

```C#
RadTabControl radTabControl = new RadTabControl();
radTabControl.DataContext = new Collection<WordDocument>();
```

```VB.NET
	Dim radTabControl As New RadTabControl()
	radTabControl.DataContext = New Collection(Of WordDocument)()
```

> The **DataContext** is inherited in the visual tree, which means that the child controls of the **RadTabControl** will have the same **DataContext**, if it is not explicitly changed.

> important The **PropagateItemDataContextToContent** property of the RadTabControl specifies whether the DataContext of the RadTabItem should be assigned as the DataContext of its content when the selection changes. The default value of this property is **True**.

## Item Source

The **ItemsSource** property allows the **RadTabControl** to be bound to any collection that implements the **IEnumerable** interface. For each item in the collection, a container of type **RadTabItem** is created. By using the **ItemTemplate**, **ItemContainerStyle** and **TemplateSelectors** you can control the appearance of the dynamically created tabs. [Read more about that here](https://www.telerik.com/products/wpf/documentation/controls/radtabcontrol/populating-with-tabs/populating-binding-to-collection).

> When binding the **RadTabControl** to a collection, the dynamically created **RadTabItems** have the item they are bound to as **DataContext**.

## Types of Sources

The **ItemsSource** property can be bound to any collection that implements the **IEnumerable** interface. If you want insertions or deletions in the collection to be automatically applied to the UI, the collection we bound to must also implement the **ICollectionChanged** interface. This interface exposes an event that should be raised whenever the underlying collection changes. In WPF there is a built-in implementation of a data collection that exposes the **INotifyCollectionChanged** interface – the **ObservableCollection<T>** class.

> tip Consider using **ObservableCollection<T>** or one of the other existing collection classes like **List<T>**, **Collection<T>**, instead of implementing your own collection. If the scenario requires a custom collection to be implemented, use the **IList** interface, which provides individual access by index to its items and the best performance.

## DisplayMemberPath

When no **ItemTemplate** is defined the **DisplayMemberPath** is used to determine which property of the **DataContext** object to be visualized in the tab content.

```XAML
<telerik:RadTabControl  ItemsSource="{Binding Persons}" DisplayMemberPath="Name" />
```

```C#
RadTabControl radTabControl2 = new RadTabControl();
radTabControl2.ItemsSource = new Collection<Person>();
radTabControl2.DisplayMemberPath = "Name";
```

```VB.NET
	Dim radTabControl As New RadTabControl()
	radTabControl.ItemsSource = New Collection(Of Person)()
	radTabControl.DisplayMemberPath = "Name"
```

> If neither the **DisplayMemberPath** nor the **ItemTemplate** are set, then the content of the tab would be set to the value returned by the **ToString()** method.

## See Also

* [Binding To Collection](https://www.telerik.com/products/wpf/documentation/controls/radtabcontrol/populating-with-tabs/populating-binding-to-collection)
* [PopulatingRadTabControl with Data](https://www.telerik.com/products/wpf/documentation/controls/radtabcontrol/getting-started/populating-with-tabs)
* [Getting Started](https://www.telerik.com/products/wpf/documentation/controls/radtabcontrol/getting-started/getting-started)
