Edit this page

Data Binding

Programmatic Data Binding

RadCarousel tries to provide an API similar to that of standard WPF ItemsControl control objects. The entry point to all data binding-related operations is RadCarousel's ItemsSource property. Providing a collection will trigger a data binding operation.

Example 1: Setting RadCarousel's ItemsSource

var dataTable = GetDataTable();
this.RadCarousel1.ItemsSource = dataTable;
Dim dataTable = GetDataTable()
Me.RadCarousel1.ItemsSource = dataTable

Unlike a standard items control, RadCarousel's ItemsSource property is declared to be of type System.Object. This lets you provide objects that are not .NET collections like the ADO.NET DataTable and DataSet:

Example 2: Providing a DataSet as an ItemsSource

var dataSet = dataTable.DataSet;
this.RadCarousel1.ItemsSource = dataSet;
Dim dataSet = dataTable.DataSet
Me.RadCarousel1.ItemsSource = dataSet

Of course standard .NET collections that implement the IEnumerable interface are fully supported as well.

Introduced to the System.ComponentModel namespace with WPF, collection views are fully supported as well.

Declarative Databinding

The ItemsSource property is visible and modifiable through XAML. Typical usage scenarios include binding to a data provider such as instances of the ObjectDataProvider or the XmlDataProvider classes.

Example 3: Setting ItemsSource through XAML

    <ObjectDataProvider x:Key="objectDataProvider" ObjectType="{x:Type e:ExamplesDB}" MethodName="GetCustomersView" />
  <telerik:RadCarousel Name="RadCarousel1"
      ItemsSource="{Binding Source={StaticResource objectDataProvider}}">

Note that you have to always pass data provider objects through a binding for the WPF bindings infrastructure to extract the data. This code will not work:

Example 4: Incorrectly setting ItemsSource through XAML

    <ObjectDataProvider x:Key="objectDataProviderIncorrect" ObjectType="{x:Type e:ExamplesDB}" MethodName="GetCustomersView" />
  <telerik:RadCarousel Name="RadCarouselIncorrect"
      ItemsSource="{StaticResource objectDataProviderIncorrect}">

As you can see, using {StaticResource objectDataProvider} directly fails to get the real data source from the data provider.

Item Source Update Notifications

To achieve better testability and loose coupling in your code it may be more convenient to manipulate data in the original data source instead of using the RadCarousel data API. RadCarousel supports that scenario by listening to data source collection change events and reflecting those changes in its visual representation. This feature is only supported for observable data sources like the WPF-native collections implementing the INotifyCollectionChanged interface or the WinForms-specific ones implementing IBindingList.

  • INotifyCollectionChanged implementors are collections that typically derive from the WPF ObservableCollection class.

  • IBindingList implementors typically inherit from the .NET BindingList generic class. Another widely-used binding list is the ADO.NET DataView.

If you need data source update notifications in your code that uses an ADO.NET DataSet or a DataTable, just change the code to bind the grid to a DataView referring the original table. The easiest way to do that is through the table's DefaultView property.