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 the RadCarousel____ItemsSource property. Providing a collection will trigger a data binding operation.

C#

this.RadCarousel1.ItemsSource = GetDataTable();

VB.NET

Me.RadCarousel1.ItemsSource = GetDataTable()

Unlike a standard items control, the RadCarousel____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. Binding to a DataSet requires that you provide additional information, the name of the contained table, by using the DataMember property:

C#

radCarousel1.DataMember = "Orders";
radCarousel1.ItemsSource = dataSet;

VB.NET

radCarousel1.DataMember = "Orders"
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.

XAML

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

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:

XAML

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

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.