DataBinding - Overview

Data binding is a process of connecting the application User Interface and business logic.

DataContext

One very important aspect of the data binding is the DataContext. It is the data object, which is assigned to the specific framework element. You can assign DataContext both through code-behind and XAML:

<telerik:RadTreeView DataContext="{StaticResource Categories}" /> 

radTreeView.DataContext = new CategoryList(); 
radTreeView.DataContext = New CategoryList() 

The DataContext property is inherited, e.g. if you assign a DataContext to an element, all of its children will automatically have the same data context, unless you assign them a different data context. For example, if you have the following control structure:

<Grid x:Name="LayoutRoot"> 
    <telerik:RadTreeView x:Name="radTreeView1"/> 
    <telerik:RadTreeView x:Name="radTreeView2"/>       
</Grid> 

You can simply assign the DataContext to the Grid control and both tree views will inherit it.

<Grid x:Name="LayoutRoot"DataContext="{StaticResource categories}"> 

Where the static resource categories is defined in XAML as follows:

<UserControl.Resources> 
  <local:CategoryList x:Key="categories" /> 
</UserControl.Resources> 

Or in code-behind:

LayoutRoot.DataContext = new CategoryList(); 
LayoutRoot.DataContext = New CategoryList() 

See Also

In this article